CMain/unittest: fix corruption issue from double free 62/203362/1
authorwansuyoo <wansu.yoo@samsung.com>
Fri, 12 Apr 2019 05:34:06 +0000 (14:34 +0900)
committerwansuyoo <wansu.yoo@samsung.com>
Fri, 12 Apr 2019 05:35:52 +0000 (14:35 +0900)
Change-Id: I0a1dbb5283f6a90d851120ca2ab0f1bb45087489
Signed-off-by: wansuyoo <wansu.yoo@samsung.com>
src/CMain/unittest/test_orchestration_server.cpp

index 8e5c4da..4f086bd 100644 (file)
@@ -174,7 +174,10 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_OwnNameFailure_ExpectedE
 
     ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE);
 
-    free(valid_GDBusConnection);
+    if (valid_GDBusConnection != NULL) {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
 }
 
 TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_SetNodeInfoNewForXMLFailure_ExpectedErrorReturn)
@@ -186,7 +189,10 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_SetNodeInfoNewForXMLFail
 
     ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE);
 
-    free(valid_GDBusConnection);
+    if (valid_GDBusConnection != NULL) {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
 }
 
 TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_ConnectionRegisterObjectFailure_ExpectedErrorReturn)
@@ -199,9 +205,18 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_ConnectionRegisterObject
 
     ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE);
 
-    free(valid_GDBusConnection);
-    free(valid_GDBusNodeInfo);
-    free(valid_GDBusinterface);
+    if (valid_GDBusConnection != NULL) {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
+    if (valid_GDBusNodeInfo != NULL) {
+        free(valid_GDBusNodeInfo);
+        valid_GDBusNodeInfo = NULL;
+    }
+    if (valid_GDBusinterface != NULL) {
+        free(valid_GDBusinterface);
+        valid_GDBusinterface = NULL;
+    }
 }
 
 TEST_F(OrchestrationServerTests, WhenCalledServerInit_ExpectedSuccess)
@@ -214,8 +229,14 @@ TEST_F(OrchestrationServerTests, WhenCalledServerInit_ExpectedSuccess)
 
     ASSERT_EQ(orchestration_server_initialize(fake_request_cb), ORCH_ERROR_NONE);
 
-    free(valid_GDBusConnection);
-    free(valid_GDBusNodeInfo);
+    if (valid_GDBusConnection != NULL) {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
+    if (valid_GDBusNodeInfo != NULL) {
+        free(valid_GDBusNodeInfo);
+        valid_GDBusNodeInfo = NULL;
+    }
     requestCbResult = false;
 }
 
@@ -242,8 +263,14 @@ TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMe
 
     EXPECT_EQ(requestCbResult, false);
 
-    free(valid_GDBusConnection);
-    free(valid_GDBusNodeInfo);
+    if (valid_GDBusConnection != NULL) {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
+    if (valid_GDBusNodeInfo != NULL) {
+        free(valid_GDBusNodeInfo);
+        valid_GDBusNodeInfo = NULL;
+    }
 }
 
 int main(int argc, char **argv)