diff options
author | Li, Xiaoming <lixm.fnst@cn.fujitsu.com> | 2020-09-18 10:27:32 +0800 |
---|---|---|
committer | Li, Xiaoming <lixm.fnst@cn.fujitsu.com> | 2020-09-18 10:27:32 +0800 |
commit | 403c69ccf1b2696275c3f3409eac7df525a26dbc (patch) | |
tree | ab2f6e8aa15cf43bc49eccc6691364ef0d943809 /helloworld-skeleton | |
parent | b4149dc39c9320503179027e3ff334f88184c48b (diff) |
Fix memory leak introduced by json_object_new_object() sololamprey_11.91.0lamprey/11.91.0koi_10.93.0koi_10.92.0koi_10.91.0koi/10.93.0koi/10.92.0koi/10.91.011.91.010.93.010.92.010.91.0
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 <lixm.fnst@cn.fujitsu.com>
Diffstat (limited to 'helloworld-skeleton')
-rw-r--r-- | helloworld-skeleton/helloworld-service-binding.c | 3 |
1 files changed, 2 insertions, 1 deletions
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; |