Fix potential memory leak 22/25922/1 10.92.0 10.93.0 11.91.0 11.92.0 12.90.0 12.90.1 12.91.0 12.92.0 12.93.0 13.93.0 koi/10.92.0 koi/10.93.0 koi_10.92.0 koi_10.93.0 lamprey/11.91.0 lamprey/11.92.0 lamprey_11.91.0 lamprey_11.92.0 marlin/12.90.0 marlin/12.90.1 marlin/12.91.0 marlin/12.92.0 marlin/12.93.0 marlin_12.90.0 marlin_12.90.1 marlin_12.91.0 marlin_12.92.0 marlin_12.93.0 needlefish/13.93.0 needlefish_13.93.0
authorLi Xiaoming <lixm.fnst@cn.fujitsu.com>
Fri, 15 Jan 2021 11:16:47 +0000 (19:16 +0800)
committerLi Xiaoming <lixm.fnst@cn.fujitsu.com>
Fri, 15 Jan 2021 11:20:26 +0000 (19:20 +0800)
It is better to init jresp as NULL, and allocate new memory when it is
used, this will avoid the memory leak if the function returns during the
process.

Bug-AGL: SPEC-3584

Change-Id: Icb1eae050294f4438ad89739e324c5483b6b3441
Signed-off-by: Li Xiaoming <lixm.fnst@cn.fujitsu.com>
binding/navigation-api.c

index 1774e29..07e5216 100644 (file)
@@ -80,7 +80,7 @@ static void navigation_subscribe_unsubscribe(afb_req_t request,
                gboolean unsub)
 {
        struct navigation_state *ns = navigation_get_userdata();
-       json_object *jresp = json_object_new_object();
+       json_object *jresp = NULL;
        const char *value;
        afb_event_t event;
        int rc;
@@ -121,6 +121,7 @@ static void navigation_subscribe_unsubscribe(afb_req_t request,
                return;
        }
 
+       jresp = json_object_new_object();
        afb_req_success_f(request, jresp, "Navigation %s to event \"%s\"",
                        !unsub ? "subscribed" : "unsubscribed",
                        value);