Fixed svace issues.
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 9 May 2018 09:25:09 +0000 (18:25 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:40:01 +0000 (19:40 +0900)
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
src/mdg.c [changed mode: 0644->0755]
src/mdg_dbus.c [changed mode: 0644->0755]
src/mdg_util.c [changed mode: 0644->0755]
src/mdg_util.h [changed mode: 0644->0755]
test/mdg-manager.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index b4c3301..482c4f1
--- a/src/mdg.c
+++ b/src/mdg.c
@@ -98,6 +98,7 @@ EXPORT_API int mdg_deinitialize(mdg_h handle)
                /* LCOV_EXCL_START */
                _DBG("all connections closed\n");
                ref_count = 0;
+               MDG_UNLOCK;
                return ret;
                /* LCOV_EXCL_STOP */
        }
@@ -921,10 +922,10 @@ EXPORT_API int mdg_device_info_clone(mdg_device_h target,
 
        CHECK_FEATURE_SUPPORTED(MDG_FEATURE);
 
-       mdg_device_s * dst = (mdg_device_s *)target;
+       mdg_device_s *dst = (mdg_device_s *)target;
        mdg_check_null_ret_error("target", target, MDG_ERROR_INVALID_PARAMETER);
 
-       mdg_device_s * src = (mdg_device_s *)source;
+       mdg_device_s *src = (mdg_device_s *)source;
        mdg_check_null_ret_error("source", source, MDG_ERROR_INVALID_PARAMETER);
 
        ret  = mdg_device_info_create(&target);
old mode 100644 (file)
new mode 100755 (executable)
index 510374f..1f59604
@@ -214,6 +214,7 @@ static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
                if (handle->mowned_device_found_cb.found_cb)
                        handle->mowned_device_found_cb.found_cb(device,
                                handle->mowned_device_found_cb.user_data);
+               destroy_device_handle(device);
        }
        g_variant_iter_free(iter);
 }
@@ -283,14 +284,18 @@ static void __request_result_cb(Group *object, gchar *cmd, gchar *device_id,
        g_variant_get(arg, "(iay)", &len, &iter);
 
        data = g_try_malloc0(len + 1);
+       if (data) {
+               data = NULL;
+               len = 0;
+       } else {
+               while (g_variant_iter_loop(iter, "y", &data[length]))
+                       length += 1;
 
-       while (g_variant_iter_loop(iter, "y", &data[length]))
-               length += 1;
+               data[length > len ? len : length] = '\0';
+               _DBG("Received result length %d data %s", len, data);
 
-       data[length] = '\0';
-       _DBG("Received result length %d data %s", len, data);
-
-       g_variant_iter_free(iter);
+               g_variant_iter_free(iter);
+       }
 
        if (handle->request_result_cb.result_cb)
                handle->request_result_cb.result_cb(cmd, device_id, data, len, ret,
old mode 100644 (file)
new mode 100755 (executable)
index bc91fb5..1593e6c
@@ -147,3 +147,45 @@ CREATE_DEVICE_HANDLER_ERROR:
        return NULL;
        /* LCOV_EXCL_STOP */
 }
+
+void destroy_device_handle(mdg_device_s *device)
+{
+       if (NULL == device) {
+               /* LCOV_EXCL_START */
+               _ERR("Memory allocation failed");
+               return;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (device->device_id) {
+               free(device->device_id);
+               device->device_id = NULL;
+       }
+       if (device->model_name) {
+               free(device->model_name);
+               device->model_name = NULL;
+       }
+       if (device->device_name) {
+               free(device->device_name);
+               device->device_name = NULL;
+       }
+       if (device->platform_ver) {
+               free(device->platform_ver);
+               device->platform_ver = NULL;
+       }
+       if (device->vendor_id) {
+               free(device->vendor_id);
+               device->vendor_id = NULL;
+       }
+       if (device->profile) {
+               free(device->profile);
+               device->profile = NULL;
+       }
+       if (device->ip) {
+               free(device->ip);
+               device->ip = NULL;
+       }
+       free(device);
+       device = NULL;
+}
+
old mode 100644 (file)
new mode 100755 (executable)
index 39d5d6e..56c8843
@@ -30,6 +30,7 @@ mdg_group_s *create_group_handle(char *uri_path, char *device_id,
 mdg_device_s *create_device_handle(char *device_id, char *ip, int device_type,
        int port, int sec_port, char *model_name, char *device_name,
        char *platform_ver, char *vendor_id, char *profile);
+void destroy_device_handle(mdg_device_s *device);
 
 #ifdef __cplusplus
 }
old mode 100644 (file)
new mode 100755 (executable)
index ba5670f..a299e0a
@@ -127,7 +127,7 @@ void _device_eject_result_cb(int result, void *user_data)
 static int run_device_eject(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int idx;
+       int idx = 1;
        mdg_group_h group = NULL;
        mdg_device_h device = NULL;
 
@@ -186,7 +186,7 @@ void _device_invite_result_cb(int result, void *user_data)
 static int run_device_invite(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int idx;
+       int idx = 1;
        mdg_group_h group = NULL;
        mdg_device_h device = NULL;
 
@@ -414,8 +414,8 @@ static int run_group_merge(MManager *mm, struct menu_data *menu)
 static int run_group_delete(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int idx;
-       mdg_group_h group;
+       int idx = 1;
+       mdg_group_h group = NULL;
 
        msg("Delete Group");
 
@@ -533,7 +533,7 @@ bool _device_found_cb(mdg_device_h device, void *user_data)
 static int run_devices_find(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int duration;
+       int duration = 2;
        msg("Find Devices");
 
        if (strlen(timeout))
@@ -595,8 +595,8 @@ int run_device_show_my_device(MManager *mm, struct menu_data *menu)
 static int run_group_leave(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int idx;
-       mdg_group_h group;
+       int idx = 1;
+       mdg_group_h group = NULL;
 
        msg("Leave Group");
 
@@ -668,8 +668,8 @@ static int run_group_show(MManager *mm, struct menu_data *menu)
 static int run_group_join(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int idx;
-       mdg_group_h group;
+       int idx = 1;
+       mdg_group_h group = NULL;
 
        msg("Join Group");
 
@@ -708,7 +708,7 @@ static int run_group_show_found(MManager *mm, struct menu_data *menu)
 {
        int ret;
        int count;
-       mdg_group_h *groups;
+       mdg_group_h *groups = NULL;
 
        msg("Show Found Group(s)");
 
@@ -771,7 +771,7 @@ void _group_finish_cb(int result, void *user_data)
 static int run_group_find(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int duration;
+       int duration = 2;
        msg("Find Group");
 
        if (strlen(timeout))
@@ -919,7 +919,7 @@ bool _mowned_device_found_cb(mdg_device_h device, void *user_data)
 static int run_devices_find_mowned_device(MManager *mm, struct menu_data *menu)
 {
        int ret;
-       int duration;
+       int duration = 2;
        msg("Find My Owned Devices");
 
        if (strlen(timeout))
@@ -982,6 +982,7 @@ int run_device_show_mowned_device(MManager *mm, struct menu_data *menu)
 static int run_request_create_group(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
+       int dev_idx = 1;
        int dev_count = 0;
        mdg_device_h device = NULL;
 
@@ -994,7 +995,6 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu)
                return RET_SUCCESS;
        }
 
-       int dev_idx;
        if (device_idx != NULL && strlen(device_idx)) {
                dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
                if (0 >= dev_idx) {
@@ -1028,6 +1028,8 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu)
 static int run_request_invite(MManager *mm, struct menu_data *menu)
 {
        int ret = 0;
+       int grp_idx = 1;
+       int dev_idx = 1;
        int grp_count = 0;
        int dev_count = 0;
        mdg_device_h device = NULL;
@@ -1041,7 +1043,6 @@ static int run_request_invite(MManager *mm, struct menu_data *menu)
                return RET_SUCCESS;
        }
 
-       int grp_idx;
        if (group_idx != NULL && strlen(group_idx)) {
                grp_idx = (unsigned short)strtol(group_idx, NULL, 10);
                if (0 >= grp_idx) {
@@ -1058,7 +1059,6 @@ static int run_request_invite(MManager *mm, struct menu_data *menu)
                }
        }
 
-       int dev_idx;
        if (device_idx != NULL && strlen(device_idx)) {
                dev_idx = (unsigned short)strtol(device_idx, NULL, 10);
                if (0 >= dev_idx) {