From 4fcf73385e8d7a5296b21eb0b78f12982b8138b8 Mon Sep 17 00:00:00 2001 From: Li Xiaoming Date: Mon, 1 Mar 2021 14:18:10 +0800 Subject: 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 --- binding/bluetooth-api.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'binding/bluetooth-api.c') 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"); -- cgit 1.2.3-korg