From 0a9c1be9be859595e8c3e1feea551d3acb5fd75c Mon Sep 17 00:00:00 2001 From: José Bollo Date: Wed, 1 Nov 2017 12:31:43 +0100 Subject: Fix memory bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8792ec2f118f40cab83c2dd336d1a341d510d75e Signed-off-by: José Bollo --- hal-interface.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hal-interface.c b/hal-interface.c index b7bdc14..d706583 100644 --- a/hal-interface.c +++ b/hal-interface.c @@ -412,7 +412,7 @@ STATIC int UpdateOneSndCtl(alsaHalCtlMapT *ctl, json_object *sndCtlJ) { json_object *tmpJ, *ctlJ; json_object_object_get_ex(sndCtlJ, "name", &tmpJ); - ctl->name = (char*) json_object_get_string(tmpJ); + ctl->name = (char*) strdup(json_object_get_string(tmpJ)); json_object_object_get_ex(sndCtlJ, "id", &tmpJ); ctl->numid = json_object_get_int(tmpJ); @@ -487,20 +487,22 @@ PUBLIC int halServiceInit(const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard json_object_object_add(queryurl, "sndname", json_object_new_string(alsaHalSndCard->name)); err = afb_service_call_sync("alsacore", "halregister", queryurl, &responseJ); - json_object_put(queryurl); if (err) { AFB_NOTICE("Fail to register HAL to ALSA lowlevel binding Response='%s'", json_object_get_string(responseJ)); + json_object_put(responseJ); goto OnErrorExit; } // extract sound devidJ from HAL registration if (!json_object_object_get_ex(responseJ, "response", &tmpJ) || !json_object_object_get_ex(tmpJ, "devid", &devidJ)) { AFB_ERROR("Ooops: Internal error no devidJ return from HAL registration Response='%s'", json_object_get_string(responseJ)); + json_object_put(responseJ); goto OnErrorExit; } // save devid for future use halSndCard->devid = strdup(json_object_get_string(devidJ)); + json_object_put(responseJ); // for each Non Alsa Control callback create a custom control ctlsJ = json_object_new_array(); @@ -548,13 +550,13 @@ PUBLIC int halServiceInit(const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard // Build new queryJ to add HAL custom control if any if (json_object_array_length(ctlsJ) > 0) { queryurl = json_object_new_object(); - json_object_get(devidJ); // make sure devidJ does not get free by 1st call. - json_object_object_add(queryurl, "devid", devidJ); + json_object_object_add(queryurl, "devid", json_object_new_string(halSndCard->devid)); json_object_object_add(queryurl, "ctl", ctlsJ); json_object_object_add(queryurl, "mode", json_object_new_int(QUERY_COMPACT)); err = afb_service_call_sync("alsacore", "addcustomctl", queryurl, &responseJ); if (err) { AFB_ERROR("Fail creating HAL Custom ALSA ctls Response='%s'", json_object_get_string(responseJ)); + json_object_put(responseJ); goto OnErrorExit; } } @@ -563,6 +565,7 @@ PUBLIC int halServiceInit(const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard json_object_object_get_ex(responseJ, "response", &ctlsJ); if (json_object_get_type(ctlsJ) != json_type_array) { AFB_ERROR("Response Invalid JSON array ctls Response='%s'", json_object_get_string(responseJ)); + json_object_put(responseJ); goto OnErrorExit; } @@ -572,15 +575,16 @@ PUBLIC int halServiceInit(const char *apiPrefix, alsaHalSndCardT *alsaHalSndCard err = UpdateOneSndCtl(&halCtls[idx].ctl, ctlJ); if (err) { AFB_ERROR("Fail found MAP Alsa Low level=%s", json_object_get_string(ctlJ)); + json_object_put(responseJ); goto OnErrorExit; } } - + json_object_put(responseJ); // finally register for alsa lowlevel event queryurl = json_object_new_object(); - json_object_object_add(queryurl, "devid", devidJ); - err = afb_service_call_sync("alsacore", "subscribe", queryurl, &responseJ); + json_object_object_add(queryurl, "devid", json_object_new_string(halSndCard->devid)); + err = afb_service_call_sync("alsacore", "subscribe", queryurl, NULL); if (err) { AFB_ERROR("Fail subscribing to ALSA lowlevel events"); goto OnErrorExit; -- cgit 1.2.3-korg