Plug memory leak in json2cbor 15/23015/4
authorMats Wichmann <mats@linux.com>
Thu, 26 Oct 2017 14:12:16 +0000 (08:12 -0600)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 31 Oct 2017 11:56:01 +0000 (11:56 +0000)
In recently introduced code, a pair of temporary buffers is used
to help convert ascii digits to a number; one is a static
allocation but the other is OICMalloc'd, but was not freed.

Change-Id: Iab1e8ce48c20aa6332d375c891f6b38ecb6939e7
Bug: https://jira.iotivity.org/browse/IOT-2863
Signed-off-by: Mats Wichmann <mats@linux.com>
resource/csdk/security/tool/json2cbor.c

index 6ec3d4e..a190c34 100644 (file)
@@ -1270,6 +1270,7 @@ static OicSecCred_t *JSONToCredBinWithRowner(const char *jsonStr,OicUuid_t *rown
                 cred->privateData.data = (uint8_t *)OICCalloc(1, cred->privateData.len);
                 VERIFY_NOT_NULL(TAG, (cred->privateData.data), ERROR);
                 memcpy(cred->privateData.data, buf, cred->privateData.len);
+                OICFree(buf);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                 VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);
@@ -1297,6 +1298,7 @@ static OicSecCred_t *JSONToCredBinWithRowner(const char *jsonStr,OicUuid_t *rown
                 cred->publicData.data = (uint8_t *)OICCalloc(1, cred->publicData.len);
                 VERIFY_NOT_NULL(TAG, (cred->publicData.data), ERROR);
                 memcpy(cred->publicData.data, buf, cred->publicData.len);
+                OICFree(buf);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
 
@@ -1325,6 +1327,7 @@ static OicSecCred_t *JSONToCredBinWithRowner(const char *jsonStr,OicUuid_t *rown
                 cred->optionalData.data =  (uint8_t *)OICCalloc(1, cred->optionalData.len);
                 VERIFY_NOT_NULL(TAG, (cred->optionalData.data), ERROR);
                 memcpy(cred->optionalData.data, buf, cred->optionalData.len);
+                OICFree(buf);
 
                 cJSON *jsonEncoding = cJSON_GetObjectItem(jsonObj, OIC_JSON_ENCODING_NAME);
                 VERIFY_NOT_NULL(TAG, jsonEncoding, ERROR);