Fix memory leaks 81/125681/1
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 18 Apr 2017 10:49:52 +0000 (19:49 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Tue, 18 Apr 2017 10:49:52 +0000 (19:49 +0900)
Change-Id: I5f0131073b92e43eb7707def054524067f1820e2
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/data-control-provider.c
src/data-control-sql.c

index dda6785..4b0705a 100755 (executable)
@@ -841,7 +841,6 @@ static int __send_result(bundle *b, datacontrol_request_type type, void *data)
        if (ret != DATACONTROL_ERROR_NONE)
                g_hash_table_remove(__socket_pair_hash, caller_app_id);
 
-       bundle_free(b);
        return ret;
 }
 
@@ -1834,6 +1833,7 @@ int datacontrol_provider_send_select_result_without_data(int request_id, int *fd
        }
        res = __set_result(b, DATACONTROL_TYPE_SQL_SELECT, NULL);
        ret = __send_result(res, DATACONTROL_TYPE_UNDEFINED, NULL);
+       bundle_free(res);
 
        caller_app_id = (char *)bundle_get_val(b, AUL_K_CALLER_APPID);
        socket_info = g_hash_table_lookup(__socket_pair_hash, caller_app_id);
@@ -1894,6 +1894,7 @@ int datacontrol_provider_send_bulk_insert_result(int request_id, data_control_bu
        }
        res = __set_result(b, DATACONTROL_TYPE_SQL_BULK_INSERT, NULL);
        ret = __send_result(res, DATACONTROL_TYPE_SQL_BULK_INSERT, (void *)bulk_result_data);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -1918,6 +1919,7 @@ int datacontrol_provider_send_select_result(int request_id, void *db_handle)
 
        res = __set_result(b, DATACONTROL_TYPE_SQL_SELECT, db_handle);
        ret =  __send_result(res, DATACONTROL_TYPE_SQL_SELECT, db_handle);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -1943,6 +1945,7 @@ int datacontrol_provider_send_insert_result(int request_id, long long row_id)
        res = __set_result(b, DATACONTROL_TYPE_SQL_INSERT, (void *)&row_id);
 
        ret = __send_result(res, DATACONTROL_TYPE_SQL_INSERT, NULL);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -1969,6 +1972,7 @@ int datacontrol_provider_send_update_result(int request_id)
        res = __set_result(b, DATACONTROL_TYPE_SQL_UPDATE, NULL);
 
        ret = __send_result(res, DATACONTROL_TYPE_SQL_UPDATE, NULL);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -1994,6 +1998,7 @@ int datacontrol_provider_send_delete_result(int request_id)
        res = __set_result(b, DATACONTROL_TYPE_SQL_DELETE, NULL);
 
        ret = __send_result(res, DATACONTROL_TYPE_SQL_DELETE, NULL);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -2003,6 +2008,7 @@ int datacontrol_provider_send_error(int request_id, const char *error)
 {
        bundle *res;
        bundle *b;
+       int ret;
 
        LOGI("Send an error for request id: %d", request_id);
 
@@ -2016,8 +2022,10 @@ int datacontrol_provider_send_error(int request_id, const char *error)
        }
 
        res = __set_result(b, DATACONTROL_TYPE_ERROR, (void *)error);
+       ret = __send_result(res, DATACONTROL_TYPE_ERROR, NULL);
+       bundle_free(res);
 
-       return __send_result(res, DATACONTROL_TYPE_ERROR, NULL);
+       return ret;
 }
 
 
@@ -2039,6 +2047,7 @@ int datacontrol_provider_send_map_bulk_add_result(int request_id, data_control_b
        }
        res = __set_result(b, DATACONTROL_TYPE_MAP_BULK_ADD, NULL);
        ret = __send_result(res, DATACONTROL_TYPE_MAP_BULK_ADD, (void *)bulk_result_data);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -2064,6 +2073,7 @@ int datacontrol_provider_send_map_result(int request_id)
        res = __set_result(b, DATACONTROL_TYPE_UNDEFINED, NULL);
 
        ret = __send_result(res, DATACONTROL_TYPE_UNDEFINED, NULL);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
@@ -2093,6 +2103,7 @@ int datacontrol_provider_send_map_get_value_result(int request_id, char **value_
        res = __set_result(b, DATACONTROL_TYPE_MAP_GET, value_list);
 
        ret = __send_result(res, DATACONTROL_TYPE_MAP_GET, value_list);
+       bundle_free(res);
        g_hash_table_remove(__request_table, &request_id);
 
        return ret;
index 406417a..885d9ec 100755 (executable)
@@ -125,8 +125,6 @@ static void __sql_call_cb(const char *provider_id, int request_id,
        }
 
        datacontrol_sql_destroy(provider);
-       if (bulk_results)
-               datacontrol_bulk_result_data_destroy(bulk_results);
 }
 
 static void __sql_instance_free(void *datacontrol_sql_instance)
@@ -299,6 +297,9 @@ static int __sql_handle_cb(bundle *b, void *data, int fd, int request_id)
                ret = DATACONTROL_ERROR_INVALID_PARAMETER;
        }
 
+       if (bulk_results)
+               datacontrol_bulk_result_data_destroy(bulk_results);
+
        return ret;
 }