Fixed memory leak detected by valgrind 27/18227/9
authorJaewook Jung <jw0213.jung@samsung.com>
Tue, 28 Mar 2017 00:04:26 +0000 (09:04 +0900)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Fri, 31 Mar 2017 19:34:31 +0000 (19:34 +0000)
Fixed memory leak detected by valgrind

Change-Id: I96c4d0816ea5be4a90e20af59e64ea3aec454c27
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18227
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/connectivity/src/caretransmission.c
resource/csdk/connectivity/test/cablocktransfertest.cpp
resource/csdk/connectivity/test/caprotocolmessagetest.cpp
resource/csdk/connectivity/test/uqueue_test.cpp

index 535e48c..4435ef6 100644 (file)
@@ -643,6 +643,7 @@ CAResult_t CARetransmissionDestroy(CARetransmission_t *context)
         }
         CAFreeEndpoint(data->endpoint);
         OICFree(data->pdu);
+        OICFree(data);
     }
     oc_mutex_unlock(context->threadMutex);
 
index 5e89e35..2ec2c25 100644 (file)
@@ -721,6 +721,10 @@ TEST_F(CABlockTransferTests, CAUpdatePayloadToCADataWithRequest)
     EXPECT_EQ(CA_STATUS_OK, CAUpdatePayloadToCAData(&cadata, payload, payloadLen));
 
     EXPECT_STREQ((const char*) payload, (const char*) cadata.requestInfo->info.payload);
+
+    free(cadata.requestInfo->info.payload);
+    CADestroyToken(tempToken);
+    CADestroyEndpoint(tempRep);
 }
 
 TEST_F(CABlockTransferTests, CAUpdatePayloadToCADataWithResponse)
@@ -755,4 +759,8 @@ TEST_F(CABlockTransferTests, CAUpdatePayloadToCADataWithResponse)
     EXPECT_EQ(CA_STATUS_OK, CAUpdatePayloadToCAData(&cadata, payload, payloadLen));
 
     EXPECT_STREQ((const char*) payload, (const char*) cadata.responseInfo->info.payload);
+
+    free(cadata.responseInfo->info.payload);
+    CADestroyToken(tempToken);
+    CADestroyEndpoint(tempRep);
 }
index a31ed6e..21f08f4 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "gtest/gtest.h"
 
+#include "oic_malloc.h"
 #include "caprotocolmessage.h"
 
 namespace {
@@ -218,6 +219,8 @@ TEST(CAProtocolMessage, CAGetTokenFromPDU)
     outData.type = CA_MSG_NONCONFIRM;
 
     EXPECT_EQ(CA_STATUS_OK, CAGetTokenFromPDU(pdu->transport_hdr, &outData, &tempRep));
+
+    OICFree(outData.token);
     coap_delete_list(options);
     coap_delete_pdu(pdu);
 }
@@ -253,6 +256,8 @@ TEST(CAProtocolMessage, CAGetInfoFromPDU)
     memset(&outData, 0, sizeof(CAInfo_t));
 
     EXPECT_EQ(CA_STATUS_OK, CAGetInfoFromPDU(pdu, &tempRep, &code, &outData));
+
+    OICFree(outData.token);
     coap_delete_list(options);
     coap_delete_pdu(pdu);
 }
index f461d46..ba439a9 100644 (file)
@@ -157,6 +157,7 @@ TEST_F(UQueueF, Get)
     {
         u_queue_message_t *value = u_queue_get_element(queue);
         ASSERT_TRUE(value != NULL);
+        OICFree(value);
     }
 }