Fix memory leaks 32/154732/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 11 Oct 2017 07:40:51 +0000 (16:40 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 11 Oct 2017 07:40:51 +0000 (16:40 +0900)
Change-Id: I0ffca49978f84cab61fa4e190588e26f00cacffc
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/vc_dbus.c
client/vc_mgr_dbus.c
client/vc_setting_dbus.c
client/vc_widget_dbus.c
common/vc_cmd_db.c
common/vc_json_parser.c
server/vcd_dbus.c
server/vcd_server.c

index 245ea13d4f13eaee00864842fd41c3e173621f67..7e690698b41d6db24de7764f893ac911a4633b7a 100644 (file)
@@ -191,12 +191,10 @@ 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;
        }
 }
index e3a2f73b9dc2985821fa7519bf705a0c542df269..a552504235dbfe4dc01f13d475937423fc914924 100644 (file)
@@ -594,12 +594,10 @@ 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;
        }
 }
index 7f6b7d87f86bdd6652fcd133dfe587e8acd41f0a..3da5868b4171f9b1fa35a9744b55b29ce6c72fa8 100755 (executable)
@@ -103,12 +103,10 @@ static void __vc_setting_dbus_connection_free()
 {
        if (NULL != g_s_conn_listener) {
                dbus_connection_close(g_s_conn_listener);
-               dbus_connection_unref(g_s_conn_listener);
                g_s_conn_listener = NULL;
        }
        if (NULL != g_s_conn_sender) {
                dbus_connection_close(g_s_conn_sender);
-               dbus_connection_unref(g_s_conn_sender);
                g_s_conn_sender = NULL;
        }
 }
index 0ef7019dbae162f50ce323798757e199864835f5..adebea10af4d4e405b1a3434fe45784dfd9e32f2 100644 (file)
@@ -266,12 +266,10 @@ 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;
        }
 }
index 43642daad80dd91ad7ac99f0bff474a1e1fdac9f..b60d7782da38a31f492d57e44097be4fdc658c29 100644 (file)
@@ -392,6 +392,9 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list)
                                free(temp_text);
                                temp_text = NULL;
 
+                               vc_cmd_destroy(temp_cmd);
+                               temp_cmd = NULL;
+
                                ret = sqlite3_step(stmt);
                                if (SQLITE_DONE == ret)
                                        break;
@@ -442,7 +445,8 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list)
                } else {
                        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);
+                       vc_cmd_destroy(temp_cmd);
+                       temp_cmd = NULL;
                }
                ret = sqlite3_step(stmt);
                if (SQLITE_DONE == ret)
index 6e715ab29a4e7479afd67cbc0f4bace7149feed8..79e6b3148c41cd799e9d938738bd2db45fbaa553 100755 (executable)
@@ -131,6 +131,10 @@ static int __vc_json_set_commands(JsonObject *root_obj, int type, char* invocati
        ret = vc_db_begin_transaction();
        if (0 != ret) {
                SLOG(LOG_ERROR, vc_json_tag(), "[ERROR] Fail to begin transaction for db");
+               free(temp_type);
+               free(prev_appid);
+               temp_type = NULL;
+               prev_appid = NULL;
                return ret;
        }
 
index 22562b5be5fbb3de3f2727ead9c84a101ed09407..0f05eede381f2ddeedce1d1aa561836cf6d9c21f 100755 (executable)
@@ -614,6 +614,7 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char*
 
        char* disp_null = NULL;
        char* utt_null = NULL;
+       int ret = VCD_ERROR_NONE;
        if (NULL == disp_text) {
                disp_null = strdup("#NULL");
                disp_text = disp_null;
@@ -635,7 +636,7 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char*
 
        if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
                SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to Send");
-               return VCD_ERROR_OPERATION_FAILED;
+               ret = VCD_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] SUCCESS Send");
                dbus_connection_flush(g_conn_sender);
@@ -653,7 +654,7 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char*
                utt_null = NULL;
        }
 
-       return 0;
+       return ret;
 }
 
 int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg)
@@ -1163,9 +1164,6 @@ int vcd_dbus_close_connection()
        dbus_connection_close(g_conn_listener);
        dbus_connection_close(g_conn_sender);
 
-       dbus_connection_unref(g_conn_listener);
-       dbus_connection_unref(g_conn_sender);
-
        g_conn_listener = NULL;
        g_conn_sender = NULL;
 
index 0129914cb5883e06c38b997106b5b4fa850556d3..ceaf32250d340d7bd8de9fab684290e356fbd5aa 100755 (executable)
@@ -570,13 +570,14 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
                        if (top_priority == temp_cmd->priority) {
                                filtered_id[filtered_count] = result_id[i];
                                filtered_count++;
-                       } else if (top_priority < temp_cmd->priority) {
-                               continue;
-                       } else {
+                       } else if (top_priority > temp_cmd->priority) {
                                filtered_id[0] = result_id[i];
                                filtered_count = 1;
                                top_priority = temp_cmd->priority;
                        }
+
+                       vc_cmd_destroy((vc_cmd_h)temp_cmd);
+                       temp_cmd = NULL;
                }
        }
 
@@ -610,6 +611,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
                        if (0 != vc_cmd_list_add(vc_cmd_list, (vc_cmd_h)temp_cmd)) {
                                SLOG(LOG_DEBUG, TAG_VCD, "Fail to add command to list");
                                vc_cmd_destroy((vc_cmd_h)temp_cmd);
+                               temp_cmd = NULL;
                        }
                } else {
                        SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] NOT found matached result(%d)", filtered_id[i]);
@@ -1139,8 +1141,8 @@ static void __vcd_cleanup_client(vcd_client_type_e type)
                                for (j = 0; j < g_list_length(g_proc_list); j++) {
                                        iter = g_list_nth(g_proc_list, j);
                                        if (NULL != iter) {
-                                               if (client_list[i] == GPOINTER_TO_INT(iter->data)) {
-                                                       SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
+                                               if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
+                                                       SLOG(LOG_DEBUG, TAG_VCD, "%s pid(%d) is running", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
                                                        exist = true;
                                                        break;
                                                }
@@ -1148,11 +1150,11 @@ static void __vcd_cleanup_client(vcd_client_type_e type)
                                }
 
                                if (false == exist) {
-                                       SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", client_list[i]);
+                                       SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == 1) ? "Widget" : "Manager" : "Normal", *(client_list + i));
                                        if (VCD_CLIENT_TYPE_NORMAL == type)
-                                               vcd_server_finalize(client_list[i]);
+                                               vcd_server_finalize(*(client_list + i));
                                        else if (VCD_CLIENT_TYPE_WIDGET == type)
-                                               vcd_server_widget_finalize(client_list[i]);
+                                               vcd_server_widget_finalize(*(client_list + i));
                                        else
                                                vcd_server_mgr_finalize(mgr_pid);
                                }