summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Xiaoming <lixm.fnst@cn.fujitsu.com>2021-03-01 14:18:10 +0800
committerLi Xiaoming <lixm.fnst@cn.fujitsu.com>2021-03-01 14:18:10 +0800
commit4fcf73385e8d7a5296b21eb0b78f12982b8138b8 (patch)
tree2dcb3590d0e5a3ac7c496e611f75114a11e57812
parentce5000f42dbfa854096a6e8c9da34d48ed04ef31 (diff)
Fix potential memory leak
json structure allocating code should be placed in where it is used, if there is a condition check which may cause a return before the before-mentioned place in the function. Bug-AGL: SPEC-3584 Change-Id: Ibbcae4357c6011eff29d031a853c8a0435f0a5ce Signed-off-by: Li Xiaoming <lixm.fnst@cn.fujitsu.com>
-rw-r--r--binding/bluetooth-api.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 8a9945a..3fcf841 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -812,7 +812,7 @@ static void bluetooth_subscribe_unsubscribe(afb_req_t request,
gboolean unsub)
{
struct bluetooth_state *ns = bluetooth_get_userdata(request);
- json_object *jresp = json_object_new_object();
+ json_object *jresp;
const char *value;
afb_event_t event;
int rc;
@@ -852,6 +852,7 @@ static void bluetooth_subscribe_unsubscribe(afb_req_t request,
return;
}
+ jresp = json_object_new_object();
afb_req_success_f(request, jresp, "Bluetooth %s to event \"%s\"",
!unsub ? "subscribed" : "unsubscribed",
value);
@@ -1035,6 +1036,7 @@ static void bluetooth_default_adapter(afb_req_t request)
if (rc) {
AFB_DEBUG("Request to save default adapter to persistent storage failed ");
afb_req_fail(request, "failed", "Update default adapter failed");
+ json_object_put(jresp);
return;
}
}
@@ -1043,6 +1045,7 @@ static void bluetooth_default_adapter(afb_req_t request)
json_object_object_add(jresp, "adapter", json_object_new_string(adapter_default));
} else {
afb_req_fail(request, "failed", "No default adapter");
+ json_object_put(jresp);
return;
}
afb_req_success(request, jresp, "Bluetooth - default adapter");