From 1c38aff32a08cdd65080b8baa6d4fe02ee2083a4 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Fri, 7 Dec 2018 19:20:16 +0800 Subject: [PATCH] No json_object_put() for the json_obj created by json_object_object_get_ex(). It is stated in the json_object.h from version 0.11: https://github.com/json-c/json-c/blob/json-c-0.11/json_object.h#L271 As on json-c 0.11, there's no assert to check for the ref_count, we wont get crashed. But on json-c 0.13.1 (latest release), json_object_put will check for the ref_count first, so mtcAgent will crash. Test Done: Run mtcAgent with json-c version 0.13.1 with this patch, no crash found. Closes-Bug: 1807097 Change-Id: I35e5c1cad2e16ee0b6fc639380f1bdd3b64a7018 Signed-off-by: Yan Chen --- mtce-common/src/common/jsonUtil.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/mtce-common/src/common/jsonUtil.cpp b/mtce-common/src/common/jsonUtil.cpp index 092c8387..cb8d6536 100644 --- a/mtce-common/src/common/jsonUtil.cpp +++ b/mtce-common/src/common/jsonUtil.cpp @@ -406,9 +406,6 @@ int jsonUtil_inv_load ( char * json_str_ptr, cleanup: if (raw_obj) json_object_put(raw_obj); - if (req_obj) json_object_put(req_obj); - if (next_obj) json_object_put(next_obj); - if (node_obj) json_object_put(node_obj); return (rc); } @@ -807,7 +804,6 @@ int jsonApi_auth_load ( string & hostname, struct json_object *token_obj = (struct json_object *)(NULL); struct json_object *svccat_obj = (struct json_object *)(NULL); struct json_object *tuple_obj = (struct json_object *)(NULL); - struct json_object *type_obj = (struct json_object *)(NULL); struct json_object *url_obj = (struct json_object *)(NULL); struct json_object *end_obj = (struct json_object *)(NULL); @@ -920,12 +916,6 @@ auth_load_cleanup: } json_object_put(raw_obj); } - if (token_obj) json_object_put(token_obj); - if (svccat_obj) json_object_put(svccat_obj); - if (tuple_obj) json_object_put(tuple_obj); - if (end_obj) json_object_put(end_obj); - if (url_obj) json_object_put(type_obj); - if (type_obj) json_object_put(type_obj); return (rc); } @@ -973,8 +963,6 @@ int jsonUtil_get_list ( char * json_str_ptr, string label, list & key_li get_list_cleanup: if (raw_obj) json_object_put(raw_obj); - if (label_obj) json_object_put(label_obj); - if (item_obj) json_object_put(item_obj); return (rc); } @@ -1067,8 +1055,6 @@ int jsonApi_array_value ( char * json_str_ptr, array_value_cleanup: if (raw_obj) json_object_put(raw_obj); - if (array_obj) json_object_put(array_obj); - if (tuple_obj) json_object_put(tuple_obj); if (type_obj) json_object_put(type_obj); return (rc); @@ -1149,8 +1135,6 @@ int jsonUtil_get_array_idx ( char * json_str_ptr, get_array_idx_cleanup: if (raw_obj) json_object_put(raw_obj); - if (array_obj) json_object_put(array_obj); - if (tuple_obj) json_object_put(tuple_obj); return (rc); } @@ -1203,7 +1187,6 @@ int jsonUtil_array_elements ( char * json_str_ptr, string label, int & elements array_elements_cleanup: if (raw_obj) json_object_put(raw_obj); - if (array_obj) json_object_put(array_obj); return (rc); }