From: Li Xiaoming Date: Fri, 15 Jan 2021 11:16:47 +0000 (+0800) Subject: Fix potential memory leak X-Git-Tag: 10.92.0^0 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=9f6da135fc36eea418ecc15f77f4f8ef0dea6e7b;p=apps%2Fagl-service-navigation.git Fix potential memory leak 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 --- diff --git a/binding/navigation-api.c b/binding/navigation-api.c index 1774e29..07e5216 100644 --- a/binding/navigation-api.c +++ b/binding/navigation-api.c @@ -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);