Fix memory leak 67/128767/2 accepted/tizen/unified/20170511.173630 accepted/tizen/unified/20170512.165233 submit/tizen/20170511.115134 submit/tizen/20170512.024705
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 11 May 2017 09:15:33 +0000 (18:15 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 11 May 2017 11:01:52 +0000 (20:01 +0900)
Change-Id: I6d8d02a895d84e9a9469930aef3dd2e198a30983
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/vc_cmd_db.c
common/vc_command.c
server/vcd_client_data.c
server/vcd_dbus.c
server/vcd_recorder.c

index 30e0266..2e35e84 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "vc_cmd_db.h"
 #include "vc_main.h"
-#include "voice_control_command.h"
+#include "vc_command.h"
 #include "voice_control_command_expand.h"
 
 
@@ -361,10 +361,12 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list)
 
        while (SQLITE_ROW == ret) {
                int temp = 0;
+               int ret = -1;
                char* temp_text = NULL;
-               vc_cmd_s* temp_cmd = NULL;
-               temp_cmd = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s));
-               if (NULL == temp_cmd) {
+               vc_cmd_h temp_cmd;
+               ret = vc_cmd_create(&temp_cmd);
+
+               if (0 != ret) {
                        SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory");
                        if (NULL != appid) {
                                free(appid);
@@ -380,12 +382,16 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list)
 
                temp_text = (char*)sqlite3_column_text(stmt, 7);
                if (NULL != temp_text)
-                       temp_cmd->appid = strdup(temp_text);
+                       vc_cmd_set_appid(temp_cmd, temp_text);
 
-               if (NULL != appid && NULL != temp_cmd->appid) {
-                       if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_cmd->appid, strlen(appid))) {
+               ret = vc_cmd_get_appid(temp_cmd, &temp_text);
+               if (NULL != appid && 0 == ret) {
+                       if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_text, strlen(appid))) {
                                SLOG(LOG_DEBUG, vc_db_tag(), "Skip get background commands when app is foreground, appid(%s)", appid);
 
+                               free(temp_text);
+                               temp_text = NULL;
+
                                ret = sqlite3_step(stmt);
                                if (SQLITE_DONE == ret)
                                        break;
@@ -394,41 +400,49 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list)
                        }
                }
 
+               if (NULL != temp_text) {
+                       free(temp_text);
+                       temp_text = NULL;
+               }
+
                temp = sqlite3_column_int(stmt, 0);
-               temp_cmd->id = temp;
+               vc_cmd_set_id(temp_cmd, temp);
 
                temp = sqlite3_column_int(stmt, 1);
-               temp_cmd->pid = temp;
+               vc_cmd_set_pid(temp_cmd, temp);
 
                temp = sqlite3_column_int(stmt, 2);
-               temp_cmd->type = temp;
+               vc_cmd_set_type(temp_cmd, temp);
 
                temp = sqlite3_column_int(stmt, 3);
-               temp_cmd->format = temp;
+               vc_cmd_set_format(temp_cmd, temp);
 
                temp  = sqlite3_column_int(stmt, 4);
-               temp_cmd->domain = temp;
+               vc_cmd_set_domain(temp_cmd, temp);
 
                temp_text = (char*)sqlite3_column_text(stmt, 5);
                if (NULL != temp_text)
-                       temp_cmd->command = strdup(temp_text);
+                       vc_cmd_set_command(temp_cmd, temp_text);
 
                temp_text = (char*)sqlite3_column_text(stmt, 6);
                if (NULL != temp_text)
-                       temp_cmd->parameter = strdup(temp_text);
+                       vc_cmd_set_unfixed_command(temp_cmd, temp_text);
 
                temp_text = (char*)sqlite3_column_text(stmt, 8);
                if (NULL != temp_text)
-                       temp_cmd->invocation_name = strdup(temp_text);
+                       vc_cmd_set_invocation_name(temp_cmd, temp_text);
 
                temp_text = (char*)sqlite3_column_text(stmt, 9);
                if (NULL != temp_text)
-                       temp_cmd->fixed = strdup(temp_text);
+                       vc_cmd_set_fixed_command(temp_cmd, temp_text);
 
-               if (type == temp_cmd->type) {
+               ret = vc_cmd_get_type(temp_cmd, &temp);
+               if (0 == ret && type == temp) {
                        *cmd_list = g_slist_append(*cmd_list, temp_cmd);
                } else {
-                       SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type);
+                       SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp, type);
+
+                       vc_cmd_destroy((vc_cmd_h)temp_cmd);
                }
                ret = sqlite3_step(stmt);
                if (SQLITE_DONE == ret)
index 38f0299..1478fcd 100644 (file)
@@ -702,7 +702,6 @@ int vc_cmd_create(vc_cmd_h* vc_command)
        command->key = VC_KEY_NONE;
        command->modifier = VC_MODIFIER_NONE;
        command->invocation_name = NULL;
-       command->parameter = NULL;
        command->appid = NULL;
        command->fixed = NULL;
 
index b033950..e7a9a00 100644 (file)
@@ -942,6 +942,10 @@ int vcd_client_add(int pid)
 
        if (NULL == g_client_list) {
                SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client");
+
+               free(info);
+               info = NULL;
+
                return -1;
        } else {
                SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new client");
@@ -1263,6 +1267,10 @@ int vcd_client_widget_add(int pid)
 
        if (NULL == g_widget_list) {
                SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget");
+
+               free(info);
+               info = NULL;
+
                return -1;
        } else {
                SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new widget");
index 75a8c63..eed98a8 100644 (file)
@@ -613,10 +613,17 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char*
 
        SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous);
 
-       if (NULL == disp_text)
-               disp_text = strdup("#NULL");
-       if (NULL == utt_text)
-               utt_text = strdup("#NULL");
+       char* disp_null = NULL;
+       char* utt_null = NULL;
+       if (NULL == disp_text) {
+               disp_null = strdup("#NULL");
+               disp_text = disp_null;
+       }
+
+       if (NULL == utt_text) {
+               utt_null = strdup("#NULL");
+               utt_text = utt_null;
+       }
 
        dbus_message_append_args(msg,
                                DBUS_TYPE_INT32, &pid,
@@ -637,6 +644,16 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char*
 
        dbus_message_unref(msg);
 
+       if (NULL != disp_null) {
+               free(disp_null);
+               disp_null = NULL;
+       }
+
+       if (NULL != utt_null) {
+               free(utt_null);
+               utt_null = NULL;
+       }
+
        return 0;
 }
 
index 6202720..25df611 100644 (file)
@@ -754,7 +754,7 @@ int vcd_recorder_stop()
 #endif
        }
 
-       if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) {
+       if (NULL != g_current_audio_type && 0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) {
                vcd_recorder_set(VCP_AUDIO_ID_NONE, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1);
                vcd_engine_set_audio_type(VCP_AUDIO_ID_NONE);
        }