Fix static analysis issues 12/203812/4 accepted/tizen/unified/20190422.050007 submit/tizen/20190419.025325
authorDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 18 Apr 2019 02:06:34 +0000 (11:06 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Thu, 18 Apr 2019 06:42:56 +0000 (15:42 +0900)
Change-Id: If18854531d0555fcec4e1f65994b600f50334b69

src/client.cc
src/dbus.cc
src/unit_tests/unit_test.cc
tools/capmgr_test.cc

index 6a6ffcb..4c95d1c 100644 (file)
@@ -192,19 +192,17 @@ API int capmgr_app_control_create(capmgr_app_control_h* app_control) {
     return CAPMGR_ERROR_INVALID_PARAMETER;
 
   try {
-    struct capmgr_app_control_s* control = new struct capmgr_app_control_s();
+    std::unique_ptr<capmgr_app_control_s> control(new capmgr_app_control_s());
     control->b = bundle_create();
     if (!control->b) {
-      delete control;
       return CAPMGR_ERROR_OUT_OF_MEMORY;
     }
     int r = aul_svc_set_operation(control->b, AUL_SVC_OPERATION_DEFAULT);
     if (r != AUL_SVC_RET_OK) {
       bundle_free(control->b);
-      delete control;
       return CAPMGR_ERROR_OUT_OF_MEMORY;
     }
-    *app_control = control;
+    *app_control = control.release();
   } catch (const std::bad_alloc& e) {
     LOG(ERROR) << e.what();
     return CAPMGR_ERROR_OUT_OF_MEMORY;
index ec092d9..93627c3 100644 (file)
@@ -88,7 +88,8 @@ void DisposeDBusProxy(GDBusConnection* conn, GDBusProxy* proxy) {
 namespace capmgr {
 
 DBusSignal::DBusSignal(const std::string& signal_name)
-    : signal_name_ { signal_name } {}
+    : signal_name_{ signal_name }, cb_ { nullptr }, user_data_ { nullptr },
+    proxy_ { nullptr }, conn_ { nullptr } {}
 
 DBusSignal::~DBusSignal() {
   DisposeDBusProxy(this->conn_, this->proxy_);
index 3d19410..e9f439f 100644 (file)
@@ -120,8 +120,13 @@ TEST_F(UnitTest, DeviceForeachDevicesNegativeTest) {
 
 TEST_F(UnitTest, DeviceClonePositiveTest) {
   // need to get device
-  capmgr_device_h clone;
-  ASSERT_EQ(capmgr_device_clone(env->device_, &clone), CAPMGR_ERROR_NONE);
+  capmgr_device_h clone = nullptr;
+  int ret;
+  ret = capmgr_device_clone(env->device_, &clone);
+  if (clone && ret == CAPMGR_ERROR_NONE)
+    capmgr_device_destroy(clone);
+
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);
 }
 
 TEST_F(UnitTest, DeviceCloneNegativeTest) {
@@ -133,10 +138,15 @@ TEST_F(UnitTest, DeviceCloneNegativeTest) {
 }
 
 TEST_F(UnitTest, DeviceDestroyPositiveTest) {
-  capmgr_device_h clone;
-  ASSERT_EQ(capmgr_device_clone(env->device_, &clone),
-      CAPMGR_ERROR_NONE);
-  ASSERT_EQ(capmgr_device_destroy(clone), CAPMGR_ERROR_NONE);
+  capmgr_device_h clone = nullptr;
+  int ret1 = CAPMGR_ERROR_INVALID_PARAMETER;
+  int ret2 = CAPMGR_ERROR_INVALID_PARAMETER;
+  ret1 = capmgr_device_clone(env->device_, &clone);
+  if (clone && ret1 == CAPMGR_ERROR_NONE)
+    ret2 = capmgr_device_destroy(clone);
+
+  ASSERT_EQ(ret1, CAPMGR_ERROR_NONE);
+  ASSERT_EQ(ret2, CAPMGR_ERROR_NONE);
 }
 
 TEST_F(UnitTest, DeviceDestroyNegativeTest) {
@@ -146,9 +156,10 @@ TEST_F(UnitTest, DeviceDestroyNegativeTest) {
 #define DEVICE_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR)      \
 TEST_F(UnitTest, POSITIVE_TESTNAME) {                                          \
   char* ATTR = nullptr;                                                        \
-  ASSERT_EQ(capmgr_device_get_##ATTR(env->device_, &ATTR), CAPMGR_ERROR_NONE); \
+  int ret = capmgr_device_get_##ATTR(env->device_, &ATTR);                     \
   ASSERT_NE(ATTR, nullptr);                                                    \
   free(ATTR);                                                                  \
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);                                           \
 }                                                                              \
                                                                                \
 TEST_F(UnitTest, NEGATIVE_TESTNAME) {                                          \
@@ -178,9 +189,11 @@ DEVICE_GET_TEST_BLOCK(DeviceGetSWVerPositiveTest,
     DeviceGetSWVerNegativeTest, sw_ver)
 
 TEST_F(UnitTest, AppControlCreatePositiveTest) {
-  capmgr_app_control_h app_control;
-  ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE);
-  capmgr_app_control_destroy(app_control);
+  capmgr_app_control_h app_control = nullptr;
+  int ret = capmgr_app_control_create(&app_control);
+  if (app_control && ret == CAPMGR_ERROR_NONE)
+    capmgr_app_control_destroy(app_control);
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);
 }
 
 TEST_F(UnitTest, AppControlCreateNegativeTest) {
@@ -188,9 +201,10 @@ TEST_F(UnitTest, AppControlCreateNegativeTest) {
 }
 
 TEST_F(UnitTest, AppControlDestroyPositiveTest) {
-  capmgr_app_control_h app_control;
-  ASSERT_EQ(capmgr_app_control_create(&app_control), CAPMGR_ERROR_NONE);
+  capmgr_app_control_h app_control = nullptr;
+  int ret = capmgr_app_control_create(&app_control);
   ASSERT_EQ(capmgr_app_control_destroy(app_control), CAPMGR_ERROR_NONE);
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);
 }
 
 TEST_F(UnitTest, AppControlDestroyNegativeTest) {
@@ -216,10 +230,10 @@ TEST_F(UnitTest, AppControlGetDeviceNegativeTest) {
 #define APP_CONTROL_GET_TEST_BLOCK(POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR) \
 TEST_F(UnitTest, POSITIVE_TESTNAME) {                                          \
   char* ATTR = nullptr;                                                        \
-  ASSERT_EQ(capmgr_app_control_get_##ATTR(env->app_control_, &ATTR),           \
-      CAPMGR_ERROR_NONE);                                                      \
+  int ret = capmgr_app_control_get_##ATTR(env->app_control_, &ATTR);           \
   ASSERT_NE(ATTR, nullptr);                                                    \
   free(ATTR);                                                                  \
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);                                           \
 }                                                                              \
                                                                                \
 TEST_F(UnitTest, NEGATIVE_TESTNAME) {                                          \
@@ -244,10 +258,11 @@ APP_CONTROL_GET_TEST_BLOCK(AppControlGetAppidPositiveTest,
 
 TEST_F(UnitTest, AppControlGetExtraDataPositiveTest) {
   char* value = nullptr;
-  ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_,
-      kExtraDataKeyStr, &value), CAPMGR_ERROR_NONE);
+  int ret = capmgr_app_control_get_extra_data(env->app_control_,
+      kExtraDataKeyStr, &value);
   ASSERT_NE(value, nullptr);
   free(value);
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);
 }
 
 TEST_F(UnitTest, AppControlGetExtraDataNegativeTest) {
@@ -323,9 +338,11 @@ TEST_F(UnitTest, AppControlRemoveExtraDataPositiveTest) {
       capmgr_app_control_remove_extra_data(env->app_control_, "key2"),
       CAPMGR_ERROR_NONE);
   // should return such as CAPMGR_ERROR_NO_SUCH_KEY?
-  char* value;
-  ASSERT_EQ(capmgr_app_control_get_extra_data(env->app_control_,
-      "key2", &value), CAPMGR_ERROR_INVALID_PARAMETER);
+  char* value = nullptr;
+  int ret = capmgr_app_control_get_extra_data(env->app_control_, "key2",
+      &value);
+  free(value);
+  ASSERT_EQ(ret, CAPMGR_ERROR_INVALID_PARAMETER);
 }
 
 TEST_F(UnitTest, AppControlRemoveExtraDataNegativeTest) {
@@ -365,10 +382,10 @@ TEST_F(UnitTest, AppInfoForeachPackagesNegativeTest) {
     POSITIVE_TESTNAME, NEGATIVE_TESTNAME, ATTR)                                \
 TEST_F(UnitTest, POSITIVE_TESTNAME) {                                          \
   char* ATTR = nullptr;                                                        \
-  ASSERT_EQ(capmgr_app_info_get_##ATTR(env->app_, &ATTR),              \
-      CAPMGR_ERROR_NONE);                                                      \
+  int ret = capmgr_app_info_get_##ATTR(env->app_, &ATTR);                      \
   ASSERT_NE(ATTR, nullptr);                                                    \
   free(ATTR);                                                                  \
+  ASSERT_EQ(ret, CAPMGR_ERROR_NONE);                                           \
 }                                                                              \
                                                                                \
 TEST_F(UnitTest, NEGATIVE_TESTNAME) {                                          \
index 789bf9c..f1779fc 100644 (file)
@@ -161,6 +161,7 @@ int AppForeachCb(const capmgr_app_info_h remote_app_info,
   free(appid);
   free(pkgid);
   free(label);
+  free(device_id);
   free(ver);
   capmgr_device_destroy(device);