From 403c69ccf1b2696275c3f3409eac7df525a26dbc Mon Sep 17 00:00:00 2001 From: "Li, Xiaoming" Date: Fri, 18 Sep 2020 10:27:32 +0800 Subject: Fix memory leak introduced by json_object_new_object() solo Everytime we call json_object_new_object() to new a json object, if we don't call json_object_object_add()(or other json-c functions) to transfer the ownership and return ,there will be some unfreeed memory. This patch will move the memory allocating code to the place only where it is needed. Bug-AGL: SPEC-3584 Change-Id: I6b67f82035eaf44e38a14c3e21b3b24c40c1f645 Signed-off-by: Li, Xiaoming --- helloworld-skeleton/helloworld-service-binding.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'helloworld-skeleton') diff --git a/helloworld-skeleton/helloworld-service-binding.c b/helloworld-skeleton/helloworld-service-binding.c index a39da57..741f955 100644 --- a/helloworld-skeleton/helloworld-service-binding.c +++ b/helloworld-skeleton/helloworld-service-binding.c @@ -36,7 +36,7 @@ static void pingSample(afb_req_t request) static void testArgsSample(afb_req_t request) { json_object *tmpJ; - json_object *res = json_object_new_object(); + json_object *res = NULL; json_object *queryJ = afb_req_json(request); json_bool success = json_object_object_get_ex(queryJ, "cezam", &tmpJ); @@ -51,6 +51,7 @@ static void testArgsSample(afb_req_t request) } if (strncmp(json_object_get_string(tmpJ), "open", 4) == 0) { + res = json_object_new_object(); json_object_object_add(res, "code", json_object_new_int(123456789)); afb_req_success(request, res, NULL); return; -- cgit 1.2.3-korg