From: Wonnam Jang Date: Mon, 5 Dec 2016 02:14:43 +0000 (+0900) Subject: Fix invocation name problem after crash X-Git-Tag: accepted/tizen/common/20161212.185435~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9d12f640b9a5b60952f403ee796f4e168ccc6c3;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Fix invocation name problem after crash Change-Id: I3930fe28d9891470db2c8e878480c06deedf1fdd Signed-off-by: Wonnam Jang --- diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c old mode 100755 new mode 100644 index 00c7ce4..aa19fc0 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1005,6 +1005,60 @@ static int __vc_db_append_commands(int pid, int type, vc_cmd_list_h vc_cmd_list) return VC_DB_ERROR_NONE; } +static vc_cmd_s* __vc_db_command_copy(vc_cmd_s* src_cmd) +{ + if (NULL == src_cmd) { + SLOG(LOG_WARN, vc_db_tag(), "[Client Data] Input command is NULL"); + return NULL; + } + + vc_cmd_s* temp_cmd = NULL; + temp_cmd = (vc_cmd_s*)calloc(sizeof(vc_cmd_s), 1); + if (NULL == temp_cmd) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); + return NULL; + } + + temp_cmd->id = src_cmd->id; + temp_cmd->pid = src_cmd->pid; + temp_cmd->index = src_cmd->index; + temp_cmd->type = src_cmd->type; + temp_cmd->format = src_cmd->format; + temp_cmd->domain = src_cmd->domain; + + if (VC_COMMAND_TYPE_SYSTEM == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_SYSTEM; + else if (VC_COMMAND_TYPE_EXCLUSIVE == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_EXCLUSIVE; + else if (VC_COMMAND_TYPE_FOREGROUND == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_FOREGROUND; + else if (VC_COMMAND_TYPE_WIDGET == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_FOREGROUND; + else if (VC_COMMAND_TYPE_SYSTEM_BACKGROUND == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_SYSTEM_BACKGROUND; + else if (VC_COMMAND_TYPE_BACKGROUND == temp_cmd->type) temp_cmd->priority = VC_COMMAND_PRIORITY_BACKGROUND; + + if (NULL != src_cmd->command) { + temp_cmd->command = strdup(src_cmd->command); + } + + if (NULL != src_cmd->parameter) { + temp_cmd->parameter = strdup(src_cmd->parameter); + } + + if (NULL != src_cmd->appid) { + temp_cmd->appid = strdup(src_cmd->appid); + } + + if (NULL != src_cmd->invocation_name) { + temp_cmd->invocation_name = strdup(src_cmd->invocation_name); + } + + if (NULL != src_cmd->fixed) { + temp_cmd->fixed = strdup(src_cmd->fixed); + } + + temp_cmd->key = src_cmd->key; + temp_cmd->modifier = src_cmd->modifier; + + return temp_cmd; +} + int vc_db_initialize(void) { SLOG(LOG_ERROR, vc_db_tag(), "DB initialization"); @@ -1322,8 +1376,9 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) { GSList* cmd_list = NULL; char* fixed_cmd = NULL; + vc_cmd_s* tmp_cmd = __vc_db_command_copy(cmd); - int ret = __vc_db_generate_command(cmd, &fixed_cmd, &cmd_list); + 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); return ret; @@ -1338,39 +1393,41 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) temp_command = iter->data; if (NULL != temp_command) { - if (NULL != cmd->command) { - free(cmd->command); - cmd->command = NULL; + if (NULL != tmp_cmd->command) { + free(tmp_cmd->command); + tmp_cmd->command = NULL; } - cmd->command = strdup(temp_command); + tmp_cmd->command = strdup(temp_command); if (NULL != fixed_cmd) - cmd->fixed = strdup(fixed_cmd); + tmp_cmd->fixed = strdup(fixed_cmd); else - cmd->fixed = NULL; + tmp_cmd->fixed = NULL; - int ret = __vc_db_insert_commands(pid, type, cmd); + int 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; } - if (VC_COMMAND_TYPE_BACKGROUND == type && NULL != cmd->invocation_name) { + if (VC_COMMAND_TYPE_BACKGROUND == type && NULL != tmp_cmd->invocation_name) { char temp[256] = {0, }; - snprintf(temp, 256, "%s %s", cmd->invocation_name, cmd->command); - if (NULL != cmd->command) - free(cmd->command); + snprintf(temp, 256, "%s %s", tmp_cmd->invocation_name, tmp_cmd->command); + if (NULL != tmp_cmd->command) + free(tmp_cmd->command); - cmd->command = strdup(temp); + tmp_cmd->command = strdup(temp); - ret = __vc_db_insert_commands(pid, type, 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; } } @@ -1389,6 +1446,7 @@ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd) free(fixed_cmd); fixed_cmd = NULL; } + vc_cmd_destroy((vc_cmd_h)tmp_cmd); return VC_DB_ERROR_NONE; } diff --git a/common/vc_command.c b/common/vc_command.c index 6a0c91d..b085344 100755 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -726,8 +726,26 @@ int vc_cmd_destroy(vc_cmd_h vc_command) SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command); if (NULL != command) { - if (NULL != command->command) free(command->command); - if (NULL != command->parameter) free(command->parameter); + if (NULL != command->command) { + free(command->command); + command->command = NULL; + } + if (NULL != command->parameter) { + free(command->parameter); + command->parameter = NULL; + } + if (NULL != command->invocation_name) { + free(command->invocation_name); + command->invocation_name = NULL; + } + if (NULL != command->appid) { + free(command->appid); + command->appid = NULL; + } + if (NULL != command->fixed) { + free(command->fixed); + command->fixed = NULL; + } free(command); command = NULL; } @@ -1816,7 +1834,7 @@ static int __vc_cmd_tabsolute_check(const char *str, struct tm *td, int *exist) hour = hour + 12 * flag; if (12 == hour) hour = 0; - else if(24 == hour) hour = 12; + else if (24 == hour) hour = 12; } if (0 > hour || 24 <= hour || (0 == flag && 12 < hour)) {