Minor resource leaks in security test for valgrind 51/22451/2
authorMats Wichmann <mats@linux.com>
Thu, 7 Sep 2017 14:29:03 +0000 (08:29 -0600)
committerRandeep Singh <randeep.s@samsung.com>
Thu, 5 Oct 2017 03:47:07 +0000 (03:47 +0000)
(this is a cherry pick of a change in master)

These two valgrind reports are quieted (last line of each trace is
the file where the fix was made)

2 bytes in 1 blocks are definitely lost in loss record 1 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x5B3576: OICMalloc (oic_malloc.c:82)
   by 0x5B363B: OICRealloc (oic_malloc.c:113)
   by 0x522520: GetDerCrl (crlresource.c:839)
   by 0x4721E1: CRLResourceTest_GetDerCrl_Test::TestBody() (crlresourcetest.cpp:90)

2,048 bytes in 1 blocks are definitely lost in loss record 268 of 270
   at 0x4C30A1E: calloc (vg_replace_malloc.c:711)
   by 0x5B35EC: OICCalloc (oic_malloc.c:102)
   by 0x4F0245: CredToCBORPayload (credresource.c:695)
   by 0x448AE9: CredResourceTest_CredToCBORPayloadNULL_Test::TestBody() (credentialresource.cpp:221)

Change-Id: I5ecfbc68103a62ec69513edb4cb68bb5d9297392
Signed-off-by: Mats Wichmann <mats@linux.com>
(cherry picked from commit 8f1c432a9ca6074295ab65ddff3a80d44eb6dfae)

resource/csdk/security/unittest/credentialresource.cpp
resource/csdk/security/unittest/crlresourcetest.cpp

index c6c91c4..a10ac1b 100644 (file)
@@ -213,10 +213,15 @@ TEST(CredResourceTest, CredToCBORPayloadNULL)
     }
     ASSERT_TRUE(NULL != cborPayload);
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CredToCBORPayload(cred, &cborPayload, &size, secureFlag));
+    /* CredToCBORPayload allocates mem if payload is non-NULL, clean up before proceeding */
     OICFree(cborPayload);
     cborPayload = NULL;
     EXPECT_EQ(OC_STACK_OK, CredToCBORPayload(NULL, &cborPayload, &size,secureFlag));
+    OICFree(cborPayload);
+    cborPayload = NULL;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CredToCBORPayload(cred, &cborPayload, 0, secureFlag));
+    OICFree(cborPayload);
+    cborPayload = NULL;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, CredToCBORPayload(cred, NULL, &size, secureFlag));
     DeleteCredList(cred);
 }
index f5b11ea..1f29a3f 100644 (file)
@@ -89,6 +89,7 @@ TEST(CRLResourceTest, GetDerCrl)
     ByteArray crlArray = {NULL, 0};
     GetDerCrl(&crlArray);
     EXPECT_NE(static_cast<size_t>(0), crlArray.len);
+    OICFree(crlArray.data);
 }
 
 #endif