aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-11-01 12:31:43 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-11-01 12:31:43 +0100
commit0a9c1be9be859595e8c3e1feea551d3acb5fd75c (patch)
tree6c184450fa915e7518cef15fc4a7f5b1373d1f8f
parent1ec4be8b3aa2be6a62a29398ef306a5bbea46726 (diff)
Fix memory bugs
Change-Id: I8792ec2f118f40cab83c2dd336d1a341d510d75e Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--hal-interface.c18
1 files 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;