From fdb034c336bc86ad0f237009a6ea5b4d6d26faf7 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 19 Jan 2017 17:29:18 +0900 Subject: [PATCH 01/16] Fix invalid volume when recorded data is NULL Change-Id: I64fddfbc492617daf1f9f512f66c1a91db00a87a (cherry picked from commit 304379bd6ce022e7bca0ed2ca71e9d01e6e2cd51) --- client/vc_mgr.c | 4 ++++ server/vcd_recorder.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 2001006..4560dff 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -1723,6 +1723,10 @@ int vc_mgr_start(bool exclusive_command_option) } } + g_volume_db = 0; + g_prev_volume_db = 0; + g_cur_volume_db = 0; + SLOG(LOG_DEBUG, TAG_VCM, "====="); SLOG(LOG_DEBUG, TAG_VCM, " "); diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 307f75b..4d3cb7e 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -514,10 +514,12 @@ static float get_volume_decibel(char* data, int size) count++; } - if (0 == count) - rms = 0.0; - else + if (0 == count) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] NULL data"); + rms = 1.0; + } else { rms = sqrt((float)square_sum/count); + } db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16); return db; -- 2.7.4 From 7714a8c2c1515ea0ae15e829b12099f5df6c8ad9 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Fri, 20 Jan 2017 14:32:04 +0900 Subject: [PATCH 02/16] Add a checker for dbus connection Change-Id: Ib525c09d3e780bfa7f31315b5db37ab408611a91 Signed-off-by: sooyeon.kim (cherry picked from commit 8dbf7eb488f86147a28dc18f97a42d4bf1234516) --- client/vc_widget_dbus.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 6e60acc..56937b4 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -391,7 +391,7 @@ int vc_widget_dbus_close_connection() dbus_connection_unref(g_w_conn_sender); dbus_connection_unref(g_w_conn_listener); - + g_w_conn_sender = NULL; g_w_conn_listener = NULL; @@ -419,8 +419,21 @@ int vc_widget_dbus_reconnect() return 0; } +static int __dbus_check() +{ + if (NULL == g_w_conn_sender) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); + return vc_widget_dbus_reconnect(); + } + return 0; +} + int vc_widget_dbus_request_hello() { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -461,6 +474,10 @@ int vc_widget_dbus_request_hello() int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -542,6 +559,10 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p int vc_widget_dbus_request_finalize(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -614,6 +635,10 @@ int vc_widget_dbus_request_finalize(int pid) int vc_widget_dbus_request_start_recording(int pid, bool command) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -676,6 +701,10 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) int vc_widget_dbus_set_foreground(int pid, bool value) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg = NULL; int tmp_value = 0; @@ -740,6 +769,10 @@ int vc_widget_dbus_set_foreground(int pid, bool value) int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -808,6 +841,10 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) int vc_widget_dbus_request_start(int pid, int silence) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -873,6 +910,10 @@ int vc_widget_dbus_request_start(int pid, int silence) int vc_widget_dbus_request_stop(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -935,6 +976,10 @@ int vc_widget_dbus_request_stop(int pid) int vc_widget_dbus_request_cancel(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -993,4 +1038,4 @@ int vc_widget_dbus_request_cancel(int pid) } return result; -} \ No newline at end of file +} -- 2.7.4 From 7d3acf7119796b3e5fe2730336804d247ad33dfd Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Mon, 23 Jan 2017 15:58:03 +0900 Subject: [PATCH 03/16] Add foreground pid check logic Change-Id: I62f4d43f5adaf87377d998db4b4dbcc8e6534018 Signed-off-by: Kwangyoun Kim (cherry picked from commit 344f5d21211fca273d25226b0843de51a1d502d5) --- server/vcd_client_data.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ server/vcd_client_data.h | 1 + server/vcd_server.c | 3 +- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 010bde0..9b2a00f 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -1391,3 +1391,80 @@ int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable) return 0; } + +void vcd_client_update_foreground_pid() +{ + int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND; + vcd_config_get_foreground(&tmp_pid); + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", tmp_pid); + + char appid[255] = {'\0',}; + GSList *iter = NULL; + vc_client_info_s *data = NULL; + + int count = g_slist_length(g_client_list); + int i; + + if (0 == count) { + SLOG(LOG_DEBUG, TAG_VCD, "No Client"); + } else { + iter = g_slist_nth(g_client_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + data = iter->data; + + if (NULL != data) { + SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid); + memset(appid, 0, 255); + aul_app_get_appid_bypid(data->pid, appid, sizeof(appid)); + int status = aul_app_get_status(appid); + if (status == STATUS_FOCUS) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", data->pid); + vcd_config_set_foreground(data->pid, true); + if (tmp_pid != data->pid) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is different"); + } + return; + } + } + iter = g_slist_next(iter); + } + } + + widget_info_s *widget_data = NULL; + count = g_slist_length(g_widget_list); + + if (0 == count) { + SLOG(LOG_DEBUG, TAG_VCD, "No widget"); + } else { + iter = g_slist_nth(g_widget_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + widget_data = iter->data; + + if (NULL != widget_data) { + SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid); + memset(appid, 0, 255); + aul_app_get_appid_bypid(widget_data->pid, appid, sizeof(appid)); + int status = aul_app_get_status(appid); + if (status == STATUS_FOCUS) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", widget_data->pid); + vcd_config_set_foreground(widget_data->pid, true); + if (tmp_pid != widget_data->pid) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is changed"); + } + return; + } + } + iter = g_slist_next(iter); + } + } + + SLOG(LOG_INFO, TAG_VCD, "[INFO] No foreground"); + vcd_config_set_foreground(VC_RUNTIME_INFO_NO_FOREGROUND, true); + return; +} diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index d84ba3b..d38a8ba 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -152,6 +152,7 @@ int vcd_client_unset_exclusive_command(int pid); int vcd_client_save_client_info(); +void vcd_client_update_foreground_pid(); /* * widget API */ diff --git a/server/vcd_server.c b/server/vcd_server.c index 9feed7e..00f5792 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1526,11 +1526,12 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive vcd_client_set_recognition_mode(recognition_mode); if (false == exclusive_cmd) { + vcd_client_update_foreground_pid(); /* Notify show tooltip */ if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) { int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command"); + SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip show and widget command"); ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true); return 0; } -- 2.7.4 From 3403ee97db2fe169614e598cb8ac1f327774e768 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 24 Jan 2017 22:49:56 +0900 Subject: [PATCH 04/16] Fix invalid result Change-Id: I51cac04fe9e87c8b3e5fd9db73da3ada52660ef8 (cherry picked from commit 12fef272e3d75441860b0fd41c0607a747919506) --- client/vc_mgr_client.c | 5 ++++- common/vc_info_parser.c | 32 +++++++++++++++++++++++++++++--- server/vcd_server.c | 6 ++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/client/vc_mgr_client.c b/client/vc_mgr_client.c index 234d0d9..b3cf80d 100644 --- a/client/vc_mgr_client.c +++ b/client/vc_mgr_client.c @@ -798,8 +798,11 @@ int vc_mgr_client_set_all_result(vc_h vc, int event, const char* result_text) if (NULL != client->all_result_text) { free(client->all_result_text); + client->all_result_text = NULL; + } + if (NULL != result_text) { + client->all_result_text = strdup(result_text); } - client->all_result_text = strdup(result_text); return 0; } diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index f46f80a..da0ab55 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -286,11 +286,24 @@ int vc_info_parser_set_demandable_client(const char* filepath) int vc_info_parser_set_result(const char* result_text, int event, const char* msg, vc_cmd_list_h vc_cmd_list, bool exclusive) { - int ret = vc_db_insert_result(result_text, event, msg, vc_cmd_list, exclusive); + char* temp_text = NULL; + if (NULL == result_text) { + temp_text = strdup("#NULL"); + } else { + temp_text = strdup(result_text); + } + + int ret = vc_db_insert_result(temp_text, event, msg, vc_cmd_list, exclusive); if (0 != ret) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Insert db is failed, ret = %d", ret); } SLOG(LOG_DEBUG, vc_info_tag(), "[Success] Save result command file"); + + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + return ret; } @@ -301,10 +314,23 @@ int vc_info_parser_get_result(char** result_text, int* event, char** result_mess return -1; } - int ret = vc_db_get_result(result_text, event, result_message, pid, vc_cmd_list, exclusive); + char* temp_text = NULL; + int ret = vc_db_get_result(&temp_text, event, result_message, pid, vc_cmd_list, exclusive); if (0 != ret) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Insert db is failed, ret = %d", ret); } + + if (!strcmp(temp_text, "#NULL")) { + *result_text = NULL; + } else { + *result_text = strdup(temp_text); + } + + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + return ret; } @@ -670,4 +696,4 @@ int __vc_cmd_parser_print_commands(GSList* cmd_list) } return 0; -} \ No newline at end of file +} diff --git a/server/vcd_server.c b/server/vcd_server.c index 00f5792..c8b4169 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -641,9 +641,11 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int /* No result */ if (NULL != all_result) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result); - bool temp = vcd_client_manager_get_exclusive(); - vc_info_parser_set_result(all_result, event, msg, NULL, temp); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL"); } + bool temp = vcd_client_manager_get_exclusive(); + vc_info_parser_set_result(all_result, event, msg, NULL, temp); int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) { -- 2.7.4 From eb434a166dd2d93256c6396f56937e5a12e9c698 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 25 Jan 2017 19:39:51 +0900 Subject: [PATCH 05/16] Add sending error callback when start fail Change-Id: I6b77f84fc5def8a7c1c8f1ca72f4da9884721792 Signed-off-by: Wonnam Jang (cherry picked from commit 8baba0e56ea2c0e4da3a02cda25bb89daaa72ada) --- server/vcd_server.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/vcd_server.c b/server/vcd_server.c index c8b4169..de53304 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1455,13 +1455,21 @@ static int __start_internal_recognition() if (0 != vcd_client_command_collect_command()) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command"); + /* Send error cb to manager */ + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return VCD_ERROR_OPERATION_FAILED; } /* 3. Set command to engine */ ret = vcd_engine_set_commands(); if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret); + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to set commands : %d", ret); + /* Send error cb to manager */ + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1478,6 +1486,10 @@ static int __start_internal_recognition() ret = vcd_engine_recognize_start(stop_by_silence); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recognition : result(%d)", ret); + /* Send error cb to manager */ + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return VCD_ERROR_OPERATION_FAILED; } @@ -1488,6 +1500,10 @@ static int __start_internal_recognition() if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret); vcd_engine_recognize_cancel(); + /* Send error cb to manager */ + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return ret; } -- 2.7.4 From bfd134c48f23c41430cc6163e7b62ef6dc6a4410 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Fri, 3 Feb 2017 14:36:37 +0900 Subject: [PATCH 06/16] Add null checker before strcmp Change-Id: Ia596f10ff6ec3403d2516f811eef628ddf2c8977 Signed-off-by: sooyeon.kim (cherry picked from commit 00f4da760eda5e4e0c1d328f2f9c3d01e3addc58) --- common/vc_info_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index da0ab55..08db797 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -320,7 +320,7 @@ int vc_info_parser_get_result(char** result_text, int* event, char** result_mess SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Insert db is failed, ret = %d", ret); } - if (!strcmp(temp_text, "#NULL")) { + if (NULL == temp_text || !strcmp(temp_text, "#NULL")) { *result_text = NULL; } else { *result_text = strdup(temp_text); -- 2.7.4 From 2d78429c2a2adf7f1152a0c01d98fc8f5fc3e58e Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Tue, 14 Feb 2017 15:29:35 +0900 Subject: [PATCH 07/16] Fix memory leak / Add null check Change-Id: I4722250cf76b9c547126f86ad33735908d7ecfcd Signed-off-by: Suyeon Hwang (cherry picked from commit 40b947aeaf1f42c86595ba60980785b4dc4b85d0) --- client/vc_widget.c | 13 +++++++++++-- common/vc_cmd_db.c | 35 ++++++++++++++++++++++++++++------- common/vc_command.c | 7 +++++++ common/vc_config_parser.c | 1 + 4 files changed, 47 insertions(+), 9 deletions(-) mode change 100755 => 100644 common/vc_command.c diff --git a/client/vc_widget.c b/client/vc_widget.c index 98843fc..c671570 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -213,7 +213,7 @@ int vc_widget_deinitialize(vc_h vc_w) } /* no break. need to next step*/ case VC_STATE_INITIALIZED: - if (NULL != widget->conn_timer) { + if (NULL != widget && NULL != widget->conn_timer) { SLOG(LOG_DEBUG, TAG_VCW, "Connect Timer is deleted"); ecore_timer_del(widget->conn_timer); widget->conn_timer = NULL; @@ -288,7 +288,9 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Connect daemon"); vc_widget_s* widget = widget_get(vc_w); - widget->conn_timer = NULL; + if (NULL != widget) { + widget->conn_timer = NULL; + } /* request initialization */ int ret = -1; @@ -367,6 +369,13 @@ int vc_widget_prepare(vc_h vc_w) } vc_widget_s* widget = widget_get(vc_w); + if (NULL == widget) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get widget handle"); + SLOG(LOG_DEBUG, TAG_VCW, "====="); + SLOG(LOG_DEBUG, TAG_VCW, " "); + return VC_ERROR_INVALID_STATE; + } + widget->conn_timer = ecore_timer_add(0, __vc_widget_connect_daemon, (void*)vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 3a040a6..01ae1e9 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1393,6 +1393,10 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) int ret = __vc_db_generate_command(tmp_cmd, &fixed_cmd, &cmd_list); if (0 != ret) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to generate command, %d", ret); + + if (NULL != tmp_cmd) { + vc_cmd_destroy((vc_cmd_h)tmp_cmd); + } return ret; } @@ -1415,14 +1419,14 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) else tmp_cmd->fixed = NULL; - int ret = __vc_db_insert_commands(pid, type, tmp_cmd); + ret = __vc_db_insert_commands(pid, type, tmp_cmd); if (ret != VC_DB_ERROR_NONE) { if (NULL != fixed_cmd) { free(fixed_cmd); fixed_cmd = NULL; } vc_cmd_destroy((vc_cmd_h)tmp_cmd); - return ret; + break; } if (VC_COMMAND_TYPE_BACKGROUND == type && NULL != tmp_cmd->invocation_name) { @@ -1440,16 +1444,33 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) fixed_cmd = NULL; } vc_cmd_destroy((vc_cmd_h)tmp_cmd); - return ret; + break; } } - - } - if (NULL != temp_command) { + cmd_list = g_slist_remove(cmd_list, temp_command); free(temp_command); temp_command = NULL; } - iter = g_slist_next(iter); + iter = g_slist_nth(cmd_list, 0); + } + + if (VC_DB_ERROR_NONE != ret) { + while (NULL != iter) { + temp_command = iter->data; + + if (NULL != temp_command) { + cmd_list = g_slist_remove(cmd_list, temp_command); + free(temp_command); + temp_command = NULL; + } + + iter = g_slist_nth(cmd_list, 0); + } + + g_slist_free(cmd_list); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to insert command, %d", ret); + + return ret; } cmd_list = NULL; } diff --git a/common/vc_command.c b/common/vc_command.c old mode 100755 new mode 100644 index b085344..3f3f719 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -361,6 +361,9 @@ int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command) SLOG(LOG_DEBUG, TAG_VCCMD, "Free command(%p)", temp_cmd); if (NULL != temp_cmd->command) free(temp_cmd->command); if (NULL != temp_cmd->parameter) free(temp_cmd->parameter); + if (NULL != temp_cmd->appid) free(temp_cmd->appid); + if (NULL != temp_cmd->invocation_name) free(temp_cmd->invocation_name); + if (NULL != temp_cmd->fixed) free(temp_cmd->fixed); free(temp_cmd); temp_cmd = NULL; } @@ -698,6 +701,10 @@ int vc_cmd_create(vc_cmd_h* vc_command) command->priority = 0; command->key = VC_KEY_NONE; command->modifier = VC_MODIFIER_NONE; + command->invocation_name = NULL; + command->parameter = NULL; + command->appid = NULL; + command->fixed = NULL; *vc_command = (vc_cmd_h)command; diff --git a/common/vc_config_parser.c b/common/vc_config_parser.c index 92ca095..050d697 100644 --- a/common/vc_config_parser.c +++ b/common/vc_config_parser.c @@ -386,6 +386,7 @@ int vc_parser_load_config(vc_config_s** config_info) SLOG(LOG_WARN, vc_config_tag(), "[WARNING] Enabled service is wrong"); temp->enabled = false; } + xmlFree(key); } else { SLOG(LOG_WARN, vc_config_tag(), "[WARNING] Enabled service is NULL"); } -- 2.7.4 From 35d0f43aa26a1d6eb91d76dd9c627d8b7b72572b Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Tue, 21 Feb 2017 14:43:23 +0900 Subject: [PATCH 08/16] Fix memory leak Change-Id: I6ec3ee020a742aeffae127383134f575ecf704f0 Signed-off-by: Suyeon Hwang (cherry picked from commit 3fcede4baff208089bc91dae037bc8f048a7854a) --- common/vc_cmd_db.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ common/vc_info_parser.c | 11 ++++ 2 files changed, 150 insertions(+) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 01ae1e9..3cf4094 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -133,11 +133,16 @@ static int __vc_db_delete_commands(int pid, vc_cmd_type_e type, const char* appi ret = sqlite3_prepare_v2(db_handle, sql, -1, &stmt, NULL); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] sqlite3_prepare_v2: %s", sqlite3_errmsg(db_handle)); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 1, (int)type); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } @@ -147,6 +152,10 @@ static int __vc_db_delete_commands(int pid, vc_cmd_type_e type, const char* appi ret = sqlite3_bind_text(stmt, 2, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] DELETE FROM vc_info WHERE type = %d AND appid = %s", type, appid); @@ -154,6 +163,10 @@ static int __vc_db_delete_commands(int pid, vc_cmd_type_e type, const char* appi ret = sqlite3_bind_int(stmt, 2, pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] DELETE FROM vc_info WHERE type = %d AND pid = %d", type, pid); @@ -162,6 +175,10 @@ static int __vc_db_delete_commands(int pid, vc_cmd_type_e type, const char* appi ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_step: fail returned, sql(%s), ret(%d), err(%s)", sql, ret, sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } @@ -189,26 +206,35 @@ static int __vc_db_insert_commands(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) ret = sqlite3_bind_int(stmt, 2, pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 3, cmd->type); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 4, cmd->format); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 5, cmd->domain); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 6, cmd->command, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } @@ -227,23 +253,31 @@ static int __vc_db_insert_commands(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) ret = sqlite3_bind_text(stmt, 8, cmd->appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } if (VC_COMMAND_TYPE_BACKGROUND == type && NULL != cmd->invocation_name) { ret = sqlite3_bind_text(stmt, 9, cmd->invocation_name, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } } ret = sqlite3_bind_text(stmt, 10, cmd->fixed, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: err(%s)", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_step: fail returned %d, %s", ret, sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } @@ -287,12 +321,19 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) ret = sqlite3_bind_int(stmt, 1, (int)type); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } if (VC_COMMAND_TYPE_BACKGROUND != type) { ret = sqlite3_bind_int(stmt, 2, pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } @@ -305,6 +346,10 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) ret = sqlite3_step(stmt); if (ret == SQLITE_DONE) { SLOG(LOG_DEBUG, vc_db_tag(), "No matched commands"); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_NONE; } @@ -325,6 +370,11 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) free(appid); appid = NULL; } + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OUT_OF_MEMORY; } @@ -447,21 +497,28 @@ static int __vc_db_insert_result(const char* result_text, int event, const char* ret = sqlite3_bind_text(stmt, 2, result_text, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 3, event); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 4, msg, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 5, exclusive); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } @@ -471,6 +528,8 @@ static int __vc_db_insert_result(const char* result_text, int event, const char* ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_step: fail returned %d, %s", ret, sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } sqlite3_reset(stmt); @@ -493,51 +552,71 @@ static int __vc_db_insert_result(const char* result_text, int event, const char* ret = sqlite3_bind_int(stmt, 6, cmd->pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 7, cmd->type); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 8, cmd->format); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 9, cmd->domain); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 10, cmd->command, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 11, cmd->parameter, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 12, cmd->appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 13, cmd->invocation_name, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 14, cmd->fixed, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_text: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_step(stmt); if (ret != SQLITE_DONE) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_step: fail returned %d, %s", ret, sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } @@ -630,24 +709,36 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi ret = sqlite3_prepare_v2(db_handle, sql, -1, &stmt, NULL); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] sqlite3_prepare_v2: %s", sqlite3_errmsg(db_handle)); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } if (NULL != appid) { ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } else if (-1 != pid) { ret = sqlite3_bind_int(stmt, 1, pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } ret = sqlite3_step(stmt); if (ret == SQLITE_DONE) { SLOG(LOG_DEBUG, vc_db_tag(), "No matched commands"); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_NONE; } @@ -689,6 +780,12 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi free(*msg); *msg = NULL; } + + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return -1; } @@ -778,6 +875,11 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi *msg = NULL; } + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } @@ -811,17 +913,22 @@ static int __vc_db_get_appid(const char* result, GSList** app_list) ret = sqlite3_bind_int(stmt, 1, VC_COMMAND_TYPE_BACKGROUND); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_text(stmt, 2, result, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } SLOG(LOG_DEBUG, vc_db_tag(), "[SQL] SELECT * FROM vc_result WHERE type = 2 and result = %s", result); ret = sqlite3_step(stmt); if (ret == SQLITE_DONE) { SLOG(LOG_DEBUG, vc_db_tag(), "No matched commands"); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_NONE; } @@ -831,6 +938,15 @@ static int __vc_db_get_appid(const char* result, GSList** app_list) temp_app = (vc_deactivated_app_s*)calloc(1, sizeof(vc_deactivated_app_s)); if (NULL == temp_app) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] memory allcation fail"); + + if (NULL != temp_app_list) { + g_slist_free_full(temp_app_list, free); + temp_app_list = NULL; + } + + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OUT_OF_MEMORY; } @@ -869,11 +985,14 @@ int __vc_db_get_result_pid_list(const char* result, GSList** pid_list) ret = sqlite3_bind_text(stmt, 1, result, -1, SQLITE_TRANSIENT); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_step(stmt); if (ret == SQLITE_DONE) { SLOG(LOG_DEBUG, vc_db_tag(), "No matched commands"); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_NONE; } @@ -885,6 +1004,15 @@ int __vc_db_get_result_pid_list(const char* result, GSList** pid_list) temp_cmd = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s)); if (NULL == temp_cmd) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] memory allcation fail"); + + if (NULL != temp_pid_list) { + g_slist_free_full(temp_pid_list, free); + temp_pid_list = NULL; + } + + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OUT_OF_MEMORY; } @@ -928,16 +1056,21 @@ static int __vc_db_append_commands(int pid, int type, vc_cmd_list_h vc_cmd_list) ret = sqlite3_bind_int(stmt, 1, pid); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_bind_int(stmt, 2, type); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_bind_int: %s", sqlite3_errmsg(db_handle)); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } ret = sqlite3_step(stmt); if (ret == SQLITE_DONE) { SLOG(LOG_DEBUG, vc_db_tag(), "No matched commands"); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_NONE; } @@ -951,6 +1084,9 @@ static int __vc_db_append_commands(int pid, int type, vc_cmd_list_h vc_cmd_list) if (0 != vc_cmd_create(&temp_cmd)) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create command!!"); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return -1; } temp = sqlite3_column_int(stmt, 0); @@ -992,6 +1128,9 @@ static int __vc_db_append_commands(int pid, int type, vc_cmd_list_h vc_cmd_list) SLOG(LOG_DEBUG, vc_db_tag(), "Fail to add command to list"); vc_cmd_destroy(temp_cmd); vc_cmd_list_destroy(vc_cmd_list, true); + sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); + sqlite3_finalize(stmt); return VC_DB_ERROR_OPERATION_FAILED; } diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 08db797..770ca29 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -191,6 +191,12 @@ int vc_info_parser_get_demandable_clients(GSList** client_list) if (NULL == temp_client) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Memory alloc error!!"); + + if (NULL != temp_client_list) { + g_slist_free_full(temp_client_list, free); + temp_client_list = NULL; + } + xmlFree(key); xmlFreeDoc(doc); return -1; } @@ -589,6 +595,11 @@ int vc_info_parser_get_client_info(GSList** client_info_list) if (NULL == client) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Memory alloc error!!"); + + if (NULL != temp_client_list) { + g_slist_free_full(temp_client_list, free); + temp_client_list = NULL; + } xmlFreeDoc(doc); return -1; } -- 2.7.4 From 2a9554d0f6ba6bb12debc1ee4fcb4eb0fa8936f1 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 27 Feb 2017 15:41:42 +0900 Subject: [PATCH 09/16] Fix memory leak / Add type casting Change-Id: I4662a6c54b34717ef0749b8beea9a4d3e2e8d09a Signed-off-by: Suyeon Hwang (cherry picked from commit ba53ae91923a97f37f3c0020d9e192415fff8430) --- common/vc_cmd_db.c | 25 ++++++++++++++++++++++++- common/vc_command.c | 37 +++++++++++++++++++++++++++++++------ common/vc_config_parser.c | 2 ++ common/vc_info_parser.c | 16 +++++++++++++++- include/voice_control.h | 2 +- server/vcd_engine_agent.c | 23 +++++++++++++++++++---- 6 files changed, 92 insertions(+), 13 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 3cf4094..4218894 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -897,6 +897,20 @@ static int __vc_db_get_result(char** result_text, int* event, char** msg, int pi return VC_DB_ERROR_NONE; } +void __vc_db_demandable_client_free(void* data) +{ + vc_deactivated_app_s* d_app = (vc_deactivated_app_s*)data; + + if (NULL != d_app) { + if (NULL != d_app->appid) { + free(d_app->appid); + d_app->appid = NULL; + } + + free(d_app); + } +} + static int __vc_db_get_appid(const char* result, GSList** app_list) { GSList* temp_app_list = NULL; @@ -940,7 +954,7 @@ static int __vc_db_get_appid(const char* result, GSList** app_list) SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] memory allcation fail"); if (NULL != temp_app_list) { - g_slist_free_full(temp_app_list, free); + g_slist_free_full(temp_app_list, __vc_db_demandable_client_free); temp_app_list = NULL; } @@ -1225,6 +1239,9 @@ int vc_db_initialize(void) db_util_close(db_handle); db_handle = NULL; } + + free(path); + path = NULL; return VC_DB_ERROR_OPERATION_FAILED; } @@ -1234,6 +1251,9 @@ int vc_db_initialize(void) if (db_handle) db_util_close(db_handle); db_handle = NULL; + + free(path); + path = NULL; return VC_DB_ERROR_OPERATION_FAILED; } @@ -1242,6 +1262,9 @@ int vc_db_initialize(void) if (db_handle) db_util_close(db_handle); db_handle = NULL; + + free(path); + path = NULL; return VC_DB_ERROR_OPERATION_FAILED; } diff --git a/common/vc_command.c b/common/vc_command.c index 3f3f719..bd0511d 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -1738,7 +1738,12 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) ret = regexec(®[4], str, 2, pmatch, 0); if (0 == ret) { len = pmatch[1].rm_eo - pmatch[1].rm_so; - tempstr = strndup(str + pmatch[1].rm_so, len); + + if (0 > len) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); + return VC_ERROR_OPERATION_FAILED; + } + tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1759,7 +1764,12 @@ static int __vc_cmd_trelative_check(const char *str, struct tm *td, int *exist) ret = regexec(®[5], str, 2, pmatch, 0); if (0 == ret) { len = pmatch[1].rm_eo - pmatch[1].rm_so; - tempstr = strndup(str + pmatch[1].rm_so, len); + + if (0 > len) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); + return VC_ERROR_OPERATION_FAILED; + } + tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1828,7 +1838,12 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) ret = regexec(®[1], str, 2, pmatch, 0); if (0 == ret) { len = pmatch[1].rm_eo - pmatch[1].rm_so; - tempstr = strndup(str + pmatch[1].rm_so, len); + + if (0 > len) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); + return VC_ERROR_OPERATION_FAILED; + } + tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -1866,7 +1881,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) idx = 1; len = pmatch[idx].rm_eo - pmatch[idx].rm_so; if (0 < len) { - tempstr = strndup(str + pmatch[idx].rm_so, len); + tempstr = strndup(str + pmatch[idx].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -2015,7 +2030,12 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist) ret = regexec(®[9], str, 2, pmatch, 0); if (0 == ret) { len = pmatch[1].rm_eo - pmatch[1].rm_so; - tempstr = strndup(str + pmatch[1].rm_so, len); + + if (0 > len) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); + return VC_ERROR_OPERATION_FAILED; + } + tempstr = strndup(str + pmatch[1].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); @@ -2079,7 +2099,12 @@ static int __vc_cmd_dabsolute_check(const char *str, struct tm *td, int *exist) if (!m_flag) return -1; len = pmatch[2].rm_eo - pmatch[2].rm_so; - tempstr = strndup(str + pmatch[2].rm_so, len); + + if (0 > len) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid string length"); + return VC_ERROR_OPERATION_FAILED; + } + tempstr = strndup(str + pmatch[2].rm_so, (size_t)len); if (NULL == tempstr) { SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Memory allocation is failed"); diff --git a/common/vc_config_parser.c b/common/vc_config_parser.c index 050d697..eb9c867 100644 --- a/common/vc_config_parser.c +++ b/common/vc_config_parser.c @@ -225,6 +225,8 @@ int vc_parser_free_engine_info(vc_engine_info_s* engine_info) } } + g_slist_free(engine_info->languages); + if (NULL != engine_info) free(engine_info); return 0; diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 770ca29..566e83b 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -145,6 +145,20 @@ int vc_cmd_parser_append_commands(int pid, vc_cmd_type_e type, vc_cmd_list_h vc_ return ret; } +void __vc_info_parser_demandable_client_free(void* data) +{ + vc_demandable_client_s* d_client = (vc_demandable_client_s*)data; + + if (NULL != d_client) { + if (NULL != d_client->appid) { + free(d_client->appid); + d_client->appid = NULL; + } + + free(d_client); + } +} + int vc_info_parser_get_demandable_clients(GSList** client_list) { /* Check file */ @@ -193,7 +207,7 @@ int vc_info_parser_get_demandable_clients(GSList** client_list) SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Memory alloc error!!"); if (NULL != temp_client_list) { - g_slist_free_full(temp_client_list, free); + g_slist_free_full(temp_client_list, __vc_info_parser_demandable_client_free); temp_client_list = NULL; } xmlFree(key); diff --git a/include/voice_control.h b/include/voice_control.h index d8ccd26..154dce9 100644 --- a/include/voice_control.h +++ b/include/voice_control.h @@ -231,7 +231,7 @@ int vc_get_state(vc_state_e* state); * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter * @retval #VC_ERROR_PERMISSION_DENIED Permission denied * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * @pre The state should be #VC_STATE_READY. + * @pre The state should be #VC_STATE_READY. * @see vc_request_start() * @see vc_request_stop() * @see vc_request_cancel() diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 3d9ec29..8166f36 100755 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -170,10 +170,29 @@ int vcd_engine_agent_release() /* Get handle data from list */ data = iter->data; iter = g_list_remove(iter, data); + + if (NULL != data) { + if (NULL != data->engine_uuid) { + free(data->engine_uuid); + data->engine_uuid = NULL; + } + if (NULL != data->engine_name) { + free(data->engine_name); + data->engine_name = NULL; + } + if (NULL != data->engine_path) { + free(data->engine_path); + data->engine_path = NULL; + } + + free(data); + data = NULL; + } } } g_list_free(iter); + g_engine_list = NULL; /* release current engine data */ if (NULL != g_dynamic_engine.pefuncs) { @@ -1133,7 +1152,3 @@ int __log_enginelist() return 0; } - - - - -- 2.7.4 From e078a081d295e2ca1453352ffccb8e1d3a26b12e Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 6 Mar 2017 15:31:08 +0900 Subject: [PATCH 10/16] Fix dbus connection free Change-Id: I6919a56db1e341be51373c9aa0b66e4cd55bac42 Signed-off-by: Wonnam Jang (cherry picked from commit 18bc92d77bec4a6784e8ea782383140fe9d501c5) --- client/vc_dbus.c | 41 +++++++++++++++++++++++++++++++++-------- client/vc_mgr_dbus.c | 41 +++++++++++++++++++++++++++++++++-------- client/vc_widget_dbus.c | 41 +++++++++++++++++++++++++++++++++-------- 3 files changed, 99 insertions(+), 24 deletions(-) diff --git a/client/vc_dbus.c b/client/vc_dbus.c index 27f4d54..1836396 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -192,6 +192,20 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle return ECORE_CALLBACK_PASS_ON; } +static void __vc_dbus_connection_free() +{ + if (NULL != g_conn_listener) { + dbus_connection_close(g_conn_listener); + dbus_connection_unref(g_conn_listener); + g_conn_listener = NULL; + } + if (NULL != g_conn_sender) { + dbus_connection_close(g_conn_sender); + dbus_connection_unref(g_conn_sender); + g_conn_sender = NULL; + } +} + int vc_dbus_open_connection() { if (NULL != g_conn_sender && NULL != g_conn_listener) { @@ -227,6 +241,7 @@ int vc_dbus_open_connection() if (NULL == g_conn_listener) { SLOG(LOG_ERROR, TAG_VCC, "Fail to get dbus connection "); + __vc_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -248,11 +263,13 @@ int vc_dbus_open_connection() if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { SLOG(LOG_ERROR, TAG_VCC, "fail dbus_bus_request_name()"); + __vc_dbus_connection_free(); return -2; } if (NULL != g_fd_handler) { SLOG(LOG_WARN, TAG_VCC, "The handler already exists."); + __vc_dbus_connection_free(); return 0; } @@ -266,12 +283,14 @@ int vc_dbus_open_connection() if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message); dbus_error_free(&err); + __vc_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } int fd = 0; if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) { SLOG(LOG_ERROR, TAG_VCC, "fail to get fd from dbus "); + __vc_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_VCC, "Get fd from dbus : %d", fd); @@ -280,6 +299,7 @@ int vc_dbus_open_connection() g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL); if (NULL == g_fd_handler) { SLOG(LOG_ERROR, TAG_VCC, "fail to get fd handler from ecore "); + __vc_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -309,20 +329,25 @@ int vc_dbus_close_connection() dbus_error_free(&err); } - dbus_connection_close(g_conn_sender); - dbus_connection_close(g_conn_listener); - - dbus_connection_unref(g_conn_sender); - dbus_connection_unref(g_conn_listener); - - g_conn_sender = NULL; - g_conn_listener = NULL; + __vc_dbus_connection_free(); return 0; } int vc_dbus_reconnect() { + if (!g_conn_sender || !g_conn_listener) { + vc_dbus_close_connection(); + + if (0 != vc_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); + return 0; + } + bool sender_connected = dbus_connection_get_is_connected(g_conn_sender); bool listener_connected = dbus_connection_get_is_connected(g_conn_listener); SLOG(LOG_WARN, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)", diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 7133c92..fe4ad31 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -496,6 +496,20 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd return ECORE_CALLBACK_PASS_ON; } +static void __vc_mgr_dbus_connection_free() +{ + if (NULL != g_m_conn_listener) { + dbus_connection_close(g_m_conn_listener); + dbus_connection_unref(g_m_conn_listener); + g_m_conn_listener = NULL; + } + if (NULL != g_m_conn_sender) { + dbus_connection_close(g_m_conn_sender); + dbus_connection_unref(g_m_conn_sender); + g_m_conn_sender = NULL; + } +} + int vc_mgr_dbus_open_connection() { if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) { @@ -532,6 +546,7 @@ int vc_mgr_dbus_open_connection() if (NULL == g_m_conn_listener) { SLOG(LOG_ERROR, TAG_VCM, "Fail to get dbus connection "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -547,11 +562,13 @@ int vc_mgr_dbus_open_connection() if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { SLOG(LOG_ERROR, TAG_VCM, "fail dbus_bus_request_name()"); + __vc_mgr_dbus_connection_free(); return -2; } if (NULL != g_m_fd_handler) { SLOG(LOG_WARN, TAG_VCM, "The handler already exists."); + __vc_mgr_dbus_connection_free(); return 0; } @@ -565,12 +582,14 @@ int vc_mgr_dbus_open_connection() if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); dbus_error_free(&err); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } int fd = 0; if (1 != dbus_connection_get_unix_fd(g_m_conn_listener, &fd)) { SLOG(LOG_ERROR, TAG_VCM, "fail to get fd from dbus "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_VCM, "Get fd from dbus : %d", fd); @@ -580,6 +599,7 @@ int vc_mgr_dbus_open_connection() if (NULL == g_m_fd_handler) { SLOG(LOG_ERROR, TAG_VCM, "fail to get fd handler from ecore "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -609,20 +629,25 @@ int vc_mgr_dbus_close_connection() dbus_error_free(&err); } - dbus_connection_close(g_m_conn_sender); - dbus_connection_close(g_m_conn_listener); - - dbus_connection_unref(g_m_conn_sender); - dbus_connection_unref(g_m_conn_listener); - - g_m_conn_sender = NULL; - g_m_conn_listener = NULL; + __vc_mgr_dbus_connection_free(); return 0; } int vc_mgr_dbus_reconnect() { + if (!g_m_conn_sender || !g_m_conn_listener) { + vc_mgr_dbus_close_connection(); + + if (0 != vc_mgr_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect"); + return 0; + } + bool sender_connected = dbus_connection_get_is_connected(g_m_conn_sender); bool listener_connected = dbus_connection_get_is_connected(g_m_conn_listener); diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 56937b4..18dbe2c 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -268,6 +268,20 @@ static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd return ECORE_CALLBACK_PASS_ON; } +static void __vc_mgr_dbus_connection_free() +{ + if (NULL != g_w_conn_listener) { + dbus_connection_close(g_w_conn_listener); + dbus_connection_unref(g_w_conn_listener); + g_w_conn_listener = NULL; + } + if (NULL != g_w_conn_sender) { + dbus_connection_close(g_w_conn_sender); + dbus_connection_unref(g_w_conn_sender); + g_w_conn_sender = NULL; + } +} + int vc_widget_dbus_open_connection() { if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { @@ -303,6 +317,7 @@ int vc_widget_dbus_open_connection() if (NULL == g_w_conn_listener) { SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -324,11 +339,13 @@ int vc_widget_dbus_open_connection() if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()"); + __vc_mgr_dbus_connection_free(); return -2; } if (NULL != g_w_fd_handler) { SLOG(LOG_WARN, TAG_VCW, "The handler already exists."); + __vc_mgr_dbus_connection_free(); return 0; } @@ -342,12 +359,14 @@ int vc_widget_dbus_open_connection() if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); dbus_error_free(&err); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } int fd = 0; if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) { SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd); @@ -357,6 +376,7 @@ int vc_widget_dbus_open_connection() if (NULL == g_w_fd_handler) { SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore "); + __vc_mgr_dbus_connection_free(); return VC_ERROR_OPERATION_FAILED; } @@ -386,20 +406,25 @@ int vc_widget_dbus_close_connection() dbus_error_free(&err); } - dbus_connection_close(g_w_conn_sender); - dbus_connection_close(g_w_conn_listener); - - dbus_connection_unref(g_w_conn_sender); - dbus_connection_unref(g_w_conn_listener); - - g_w_conn_sender = NULL; - g_w_conn_listener = NULL; + __vc_mgr_dbus_connection_free(); return 0; } int vc_widget_dbus_reconnect() { + if (!g_w_conn_sender || !g_w_conn_listener) { + vc_widget_dbus_close_connection(); + + if (0 != vc_widget_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect"); + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect"); + return 0; + } + bool sender_connected = dbus_connection_get_is_connected(g_w_conn_sender); bool listener_connected = dbus_connection_get_is_connected(g_w_conn_listener); SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Sender(%s) Listener(%s)", -- 2.7.4 From 87db3f658e9eb08702d5dd7f7bf21f88d28f2537 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Wed, 8 Mar 2017 11:27:00 +0900 Subject: [PATCH 11/16] Add setting handle check to prevent duplicated deinitilize request Change-Id: I9d90a00a47cd055e52e361078a908a79a9ea5fd2 (cherry picked from commit 39817d7e7b505f4dbe3faec8e72c58daabebee95) --- client/vc_setting.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/vc_setting.c b/client/vc_setting.c index 28de295..3f35bb3 100644 --- a/client/vc_setting.c +++ b/client/vc_setting.c @@ -96,6 +96,7 @@ int vc_setting_initialize(void) SLOG(LOG_ERROR, TAG_VCS, "[ERROR] Fail to initialize config manager"); SLOG(LOG_DEBUG, TAG_VCS, "====="); SLOG(LOG_DEBUG, TAG_VCS, " "); + vc_config_mgr_finalize(getpid() + VC_SETTING_CONFIG_HANDLE); return VC_ERROR_OPERATION_FAILED; } @@ -113,6 +114,13 @@ int vc_setting_deinitialize() { SLOG(LOG_DEBUG, TAG_VCS, "===== Deinitialize VC Setting"); + if (VC_SETTING_STATE_READY != g_state) { + SLOG(LOG_WARN, TAG_VCS, "[WARNING] VC Setting is not initialized"); + SLOG(LOG_DEBUG, TAG_VCS, "====="); + SLOG(LOG_DEBUG, TAG_VCS, " "); + return VC_ERROR_INVALID_STATE; + } + vc_config_mgr_unset_lang_cb(getpid() + VC_SETTING_CONFIG_HANDLE); vc_config_mgr_finalize(getpid() + VC_SETTING_CONFIG_HANDLE); -- 2.7.4 From 9ee3fb6e5f84dc7d2ef1cdf367ec4a3a1400a751 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Thu, 16 Mar 2017 17:12:26 +0900 Subject: [PATCH 12/16] Set result text before selecting result when conflict status is Change-Id: If30af9e0b8d262888f9af4da06ab2f8a58fbd298 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 4560dff..cfea1e3 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2078,6 +2078,8 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) bool cb_ret; + vc_mgr_client_set_all_result(g_vc_m, event, temp_text); + vc_mgr_client_use_callback(g_vc_m); cb_ret = all_callback(event, vc_cmd_list, temp_text, temp_message, all_user_data); vc_mgr_client_not_use_callback(g_vc_m); @@ -2112,7 +2114,6 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) int count = 0; vc_cmd_list_get_count(vc_cmd_list, &count); if (0 < count) { - vc_mgr_client_set_all_result(g_vc_m, event, temp_text); if (true == cb_ret) { SLOG(LOG_DEBUG, TAG_VCM, "Callback result is true"); if (VC_RESULT_TYPE_NOTIFICATION != result_type) -- 2.7.4 From 5614bbd09b7fc3fc9ca7d2e635b58d09df6d87cc Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 17 Mar 2017 17:17:21 +0900 Subject: [PATCH 13/16] Get focused pid to set foreground Change-Id: I73848b36bb8472b1bcd4ec364607a27c22e84c63 Signed-off-by: Wonnam Jang --- server/vcd_client_data.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 9b2a00f..b033950 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -16,6 +16,7 @@ #include #include +#include #include "vcd_client_data.h" #include "vcd_config.h" @@ -1396,9 +1397,14 @@ void vcd_client_update_foreground_pid() { int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND; vcd_config_get_foreground(&tmp_pid); - SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", tmp_pid); - char appid[255] = {'\0',}; + int pid = VC_RUNTIME_INFO_NO_FOREGROUND; + int ret = aul_window_get_focused_pid(&pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get focused pid, ret(%d)", ret); + } + SLOG(LOG_INFO, TAG_VCD, "[INFO] Foreground pid (%d), Focused pid (%d)", tmp_pid, pid); + GSList *iter = NULL; vc_client_info_s *data = NULL; @@ -1417,10 +1423,7 @@ void vcd_client_update_foreground_pid() if (NULL != data) { SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid); - memset(appid, 0, 255); - aul_app_get_appid_bypid(data->pid, appid, sizeof(appid)); - int status = aul_app_get_status(appid); - if (status == STATUS_FOCUS) { + if (pid == data->pid) { SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", data->pid); vcd_config_set_foreground(data->pid, true); if (tmp_pid != data->pid) { @@ -1448,10 +1451,7 @@ void vcd_client_update_foreground_pid() if (NULL != widget_data) { SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid); - memset(appid, 0, 255); - aul_app_get_appid_bypid(widget_data->pid, appid, sizeof(appid)); - int status = aul_app_get_status(appid); - if (status == STATUS_FOCUS) { + if (pid == widget_data->pid) { SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", widget_data->pid); vcd_config_set_foreground(widget_data->pid, true); if (tmp_pid != widget_data->pid) { -- 2.7.4 From e0e37ff8cf6b14dcc68581e7f0294eb88eb8cc75 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Mon, 13 Mar 2017 16:00:56 +0900 Subject: [PATCH 14/16] Fix direct leak Change-Id: I51d8fbbaa46a3a318b3e1a3102c0e21269b9690c Signed-off-by: sooyeon.kim (cherry picked from commit b8f1f78a4f93753984e63e7ead6f246da7faf1fe) --- server/vcd_engine_agent.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 8166f36..0c9faa7 100755 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -173,15 +173,15 @@ int vcd_engine_agent_release() if (NULL != data) { if (NULL != data->engine_uuid) { - free(data->engine_uuid); + g_free(data->engine_uuid); data->engine_uuid = NULL; } if (NULL != data->engine_name) { - free(data->engine_name); + g_free(data->engine_name); data->engine_name = NULL; } if (NULL != data->engine_path) { - free(data->engine_path); + g_free(data->engine_path); data->engine_path = NULL; } @@ -266,9 +266,9 @@ int vcd_engine_agent_initialize_current_engine() } else { if (NULL != g_dynamic_engine.engine_uuid) { /* set data from g_engine_list */ - if (g_dynamic_engine.engine_uuid != NULL) free(g_dynamic_engine.engine_uuid); - if (g_dynamic_engine.engine_name != NULL) free(g_dynamic_engine.engine_name); - if (g_dynamic_engine.engine_path != NULL) free(g_dynamic_engine.engine_path); + if (g_dynamic_engine.engine_uuid != NULL) g_free(g_dynamic_engine.engine_uuid); + if (g_dynamic_engine.engine_name != NULL) g_free(g_dynamic_engine.engine_name); + if (g_dynamic_engine.engine_path != NULL) g_free(g_dynamic_engine.engine_path); } g_dynamic_engine.engine_uuid = g_strdup(dynamic_engine->engine_uuid); @@ -419,9 +419,13 @@ int __internal_update_engine_list() data = iter->data; if (NULL != data) { - if (NULL != data->engine_uuid) free(data->engine_uuid); - if (NULL != data->engine_path) free(data->engine_path); - if (NULL != data->engine_name) free(data->engine_name); + if (NULL != data->engine_uuid) g_free(data->engine_uuid); + if (NULL != data->engine_path) g_free(data->engine_path); + if (NULL != data->engine_name) g_free(data->engine_name); + + data->engine_uuid = NULL; + data->engine_path = NULL; + data->engine_name = NULL; free(data); } -- 2.7.4 From 88b4ebf37ce81917f6167985dbb780c488a19153 Mon Sep 17 00:00:00 2001 From: "Park, Sehwan" Date: Wed, 29 Mar 2017 20:50:01 +0900 Subject: [PATCH 15/16] The description related with X window system is changed Change-Id: Id1d12638b54e83af6c118d239aba4bb9425ee50c --- client/vc_widget_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc_widget_client.h b/client/vc_widget_client.h index b5c9633..55a44e3 100644 --- a/client/vc_widget_client.h +++ b/client/vc_widget_client.h @@ -31,7 +31,7 @@ typedef struct { vc_h vc; int pid; int uid; /*<< unique id = pid + handle */ - int xid; /*<< main X window id */ + int xid; /*<< main Wayland window id */ vc_result_cb result_cb; void* result_user_data; -- 2.7.4 From c15bb24cec65ecc5987adc862e70edc42ebde2be Mon Sep 17 00:00:00 2001 From: "Park, Sehwan" Date: Wed, 29 Mar 2017 21:48:20 +0900 Subject: [PATCH 16/16] Unused codes and unnecessary variable initializing are removed Change-Id: Ifb50e234008e7c0935c6fd8eb06ef11c50967661 --- client/vc_mgr.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cfea1e3..5b45991 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -559,33 +559,6 @@ int vc_mgr_set_demandable_client_rule(const char* rule) SLOG(LOG_DEBUG, TAG_VCM, " "); return 0; - - /* - int count = 0; - ret = -1; - while (0 != ret) { - ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle); - if (0 != ret) { - if (VC_ERROR_TIMED_OUT != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set client rule to daemon : %s", __vc_mgr_get_error_code(ret)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set client rule : %s", __vc_mgr_get_error_code(ret)); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } - } - } - } - - SLOG(LOG_DEBUG, TAG_VCM, "====="); - SLOG(LOG_DEBUG, TAG_VCM, " "); - - return 0; - */ } int vc_mgr_unset_demandable_client_rule() @@ -1033,12 +1006,10 @@ int vc_mgr_set_audio_type(const char* audio_id) return VC_ERROR_INVALID_STATE; } - int ret; + int ret = -1; int count = 0; /* Request */ - ret = -1; - count = 0; while (0 != ret) { ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id); if (0 != ret) { -- 2.7.4