[IOT-3106] Memory leak when converting PEM to DER 97/25997/6
authorOleksandr Andrieiev <o.andrieiev@samsung.com>
Tue, 26 Jun 2018 12:25:44 +0000 (15:25 +0300)
committerAleksey Volkov <a.volkov@samsung.com>
Fri, 29 Jun 2018 08:23:12 +0000 (08:23 +0000)
Bug: https://jira.iotivity.org/browse/IOT-3106
Change-Id: I560830d62bad76447bf1c4acaf004cc779fbcdfb
Signed-off-by: Oleksandr Andrieiev <o.andrieiev@samsung.com>
resource/csdk/security/src/credresource.c

index 08c5721..f177c92 100644 (file)
@@ -3335,17 +3335,20 @@ void GetIdentityHandler(UuidContext_t* ctx, unsigned char* crt, size_t crtLen)
             derLen = cred->publicData.len;
         }
 
-        if (derLen != crtLen)
+        if (derLen != crtLen || 0 != memcmp(der, crt, crtLen))
         {
+            if (der != cred->publicData.data)
+            {
+                OICFree(der);
+            }
             continue;
         }
-
-        if (0 != memcmp(der, crt, crtLen))
+        if (der != cred->publicData.data)
         {
-            continue;
+            OICFree(der);
         }
 
-        UuidInfo_t* node = (UuidInfo_t*) malloc(sizeof(UuidInfo_t));
+        UuidInfo_t* node = (UuidInfo_t*) OICMalloc(sizeof(UuidInfo_t));
         if (NULL == node)
         {
             OIC_LOG_V(ERROR, TAG, "%s: Could not allocate new UUID node", __func__);
@@ -3367,7 +3370,7 @@ void GetIdentityHandler(UuidContext_t* ctx, unsigned char* crt, size_t crtLen)
         else
         {
             OIC_LOG_V(ERROR, TAG, "%s: Failed to convert subjectuuid to string", __func__);
-            free(node);
+            OICFree(node);
         }
     }
 }