From 53507abedd4635f01418c1e0fd8bce1ac4cfb49b Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Tue, 16 Oct 2018 13:47:49 +0900 Subject: [PATCH] Fix svace issue Signed-off-by: Jihoon Jung Change-Id: I6c2249a42a4ee8613e2cdcee04ed6e88068cf077 --- src/mdg_util.c | 4 +-- test/mdg-manager.c | 75 +++++++++++++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/mdg_util.c b/src/mdg_util.c index 7ee9a25..3d602f6 100755 --- a/src/mdg_util.c +++ b/src/mdg_util.c @@ -64,7 +64,7 @@ mdg_device_s *mdg_get_device_from_variant(GVariant *va) char *platform_ver = NULL; char *vendor_id = NULL; char *profile = NULL; - bool is_invited; + bool is_invited = false; int type = MDG_DEVICE_TYPE_LOCAL; GVariantIter *iter = NULL; const gchar *key; @@ -135,7 +135,7 @@ void mdg_get_data_from_variant(GVariant *va, char **device_id, char **channel_id GVariantIter *iter = NULL; const gchar *key; GVariant *key_value = NULL; - GVariant *data_va; + GVariant *data_va = NULL; GVariantIter *data_iter = NULL; unsigned char byte_data; diff --git a/test/mdg-manager.c b/test/mdg-manager.c index ae23531..be694ef 100755 --- a/test/mdg-manager.c +++ b/test/mdg-manager.c @@ -77,8 +77,7 @@ void receive_request_result(char *cmd, char *device_id, unsigned char *arg, } if (strncmp("COMP_REQ_CREATE_GROUP", cmd, strlen(cmd)) == 0) { - msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret), - ret); + msgp("[CMD] Request Create Group [%s(0x%X)]", mdg_error_to_string(ret), ret); if (ret == MDG_ERROR_NONE && arg != NULL) { msgb("Created Group name is %s", arg); run_group_find(NULL, NULL); @@ -93,8 +92,7 @@ void receive_request_result(char *cmd, char *device_id, unsigned char *arg, if (ret == MDG_ERROR_NONE && arg != NULL) msgb("Ejected Device ID is %s", arg); } else if (strncmp("COMP_REQ_DELETE_GROUP", cmd, strlen(cmd)) == 0) { - msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret), - ret); + msgp("[CMD] Request Delete Group [%s(0x%X)]", mdg_error_to_string(ret), ret); if (ret == MDG_ERROR_NONE && arg != NULL) msgb("Deleted Group name is %s", arg); } else if (strncmp("COMP_REQ_SEND_DATA", cmd, strlen(cmd)) == 0) { @@ -112,7 +110,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; @@ -172,13 +170,15 @@ bool __group_foreach_cb(mdg_device_h device, void *user_data) found_invited_device_list = g_list_append(found_invited_device_list, device); + g_free(device_id); + return true; } static int run_group_foreach_device(MManager *mm, struct menu_data *menu) { int ret; - int idx; + int idx = 1; mdg_group_h group = NULL; msg("Foreach Device"); @@ -225,7 +225,7 @@ void _device_invite_result_cb(int result, mdg_device_h device, 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; @@ -465,8 +465,8 @@ static int run_group_get_members(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"); @@ -503,7 +503,6 @@ void _device_finish_cb(int result, void *user_data) bool _device_found_cb(mdg_device_h device, void *user_data) { - char *addr = NULL; char *device_id = NULL; char *model_name = NULL; mdg_device_type_e device_type; @@ -540,8 +539,6 @@ bool _device_found_cb(mdg_device_h device, void *user_data) if (device_id) free(device_id); - if (addr) - free(addr); return TRUE; } @@ -549,7 +546,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 = 0; msg("Find Devices"); if (strlen(timeout)) @@ -579,6 +576,9 @@ void __invited_event_cb(mdg_group_h group, void *user_data) mdg_group_info_get_name(group, &name); msgb("device is invited by [%s], Group Name [%s]", device_id, name); + + g_free(device_id); + g_free(name); } void __ejected_event_cb(mdg_group_h group, void *user_data) @@ -590,6 +590,9 @@ void __ejected_event_cb(mdg_group_h group, void *user_data) mdg_group_info_get_name(group, &name); msgb("device is ejected by [%s], Group Name [%s]", device_id, name); + + g_free(device_id); + g_free(name); } void __receive_file_cb(int result, char *device_id, const char *file_path, void *user_data) @@ -639,6 +642,8 @@ int run_device_show_local_device(MManager *mm, struct menu_data *menu) msgb("[Is Invited] %d", is_invited); msgb("[Type] %s\n", __device_type_to_string(type)); + if (model_name) + free(model_name); if (device_id) free(device_id); if (device_name) @@ -751,7 +756,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 = 0; msg("Find Group"); if (strlen(timeout)) @@ -814,7 +819,6 @@ static int __send_data(int devidx, int chaidx) { int ret = 0; char *deviceid = NULL; - char *address = NULL; mdg_device_h device = NULL; channel_t *channel = NULL; @@ -839,22 +843,28 @@ static int __send_data(int devidx, int chaidx) } } + if (NULL == device) { + msgr("device is NULL"); + return RET_FAILURE; + } + + if (NULL == channel) { + msgr("channel is NULL"); + return RET_FAILURE; + } + mdg_device_info_get_device_id(device, &deviceid); msgp("Sent to [ID] %s [CHANNEL ID] %s", deviceid, channel->channel_id); if (deviceid) { free(deviceid); deviceid = NULL; } - if (address) { - free(address); - address = NULL; - } int msg_id; ret = mdg_device_send_data(handle, device, channel->channel_id, (unsigned char *)message, - strlen(message), _send_data_finish_cb, NULL, &msg_id); + strlen(message), _send_data_finish_cb, NULL, &msg_id); if (MDG_ERROR_NONE != ret) - msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); + msgr("Failed to Send Data: [ID] %s", deviceid); msgp("The message ID is %d", msg_id); @@ -901,13 +911,14 @@ void __send_file_finish_cb(int result, mdg_device_h device, void *user_data) mdg_device_info_get_device_id(device, &device_id); msgp("Send file to %s Finished [%s]", device_id, mdg_error_to_string(result)); + + g_free(device_id); } static int __send_file(int devidx) { int ret = 0; char *deviceid = NULL; - char *address = NULL; mdg_device_h device = NULL; if (found_invited_device_list) { @@ -924,15 +935,11 @@ static int __send_file(int devidx) free(deviceid); deviceid = NULL; } - if (address) { - free(address); - address = NULL; - } ret = mdg_device_send_file(handle, device, file_path, __send_file_progress_cb, __send_file_finish_cb, NULL); if (MDG_ERROR_NONE != ret) - msgr("Failed to Send Data: [ID] %s [IP] %s", deviceid, address); + msgr("Failed to Send Data: [ID] %s", deviceid); return ret; } @@ -985,7 +992,7 @@ bool _invited_device_found_cb(mdg_device_h device, void *user_data) static int run_devices_find_invited_device(MManager *mm, struct menu_data *menu) { int ret; - int duration; + int duration = 0; msg("Find My Owned Devices"); if (strlen(timeout)) @@ -1025,7 +1032,7 @@ static int run_request_create_group(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int dev_idx; + int dev_idx = 1; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1072,7 +1079,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int grp_idx; + int grp_idx = 1; if (group_idx != NULL && strlen(group_idx)) { grp_idx = (unsigned short)strtol(group_idx, NULL, 10); if (0 >= grp_idx) { @@ -1089,7 +1096,7 @@ static int run_request_invite(MManager *mm, struct menu_data *menu) } } - int dev_idx; + int dev_idx = 1; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1135,7 +1142,7 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int grp_idx; + int grp_idx = 1; if (group_idx != NULL && strlen(group_idx)) { grp_idx = (unsigned short)strtol(group_idx, NULL, 10); if (0 >= grp_idx) { @@ -1152,7 +1159,7 @@ static int run_request_eject(MManager *mm, struct menu_data *menu) } } - int dev_idx; + int dev_idx = 1; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { @@ -1207,7 +1214,7 @@ static int run_request_channel_list(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } - int dev_idx; + int dev_idx = 1; if (device_idx != NULL && strlen(device_idx)) { dev_idx = (unsigned short)strtol(device_idx, NULL, 10); if (0 >= dev_idx) { -- 2.7.4