Fix memory leak 73/154473/2
authorjusung son <jusung07.son@samsung.com>
Tue, 10 Oct 2017 08:57:43 +0000 (17:57 +0900)
committerjusung son <jusung07.son@samsung.com>
Wed, 11 Oct 2017 01:39:38 +0000 (01:39 +0000)
Change-Id: If5a3d697344192fd0664a466d95a6b89472e1a30
Signed-off-by: jusung son <jusung07.son@samsung.com>
src/data_control_internal.c
src/data_control_noti.c

index 3c37947..3fe9a2e 100755 (executable)
@@ -1678,18 +1678,22 @@ int _request_provider(data_control_h provider, datacontrol_request_type type,
                                return ret;
                        }
 
-                       ret = __request_appsvc_run(caller_app_id, app_id);
-                       if (ret != DATA_CONTROL_ERROR_NONE) {
-                               bundle_free(send_data);
-                               return ret;
-                       }
-
                        socket_hash_key = strdup(provider->provider_id);
                        if (socket_hash_key == NULL) {
+                               bundle_free(send_data);
+                               _socket_info_free((gpointer)socket_info);
                                _LOGE("Out of memory");
                                return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
                        }
 
+                       ret = __request_appsvc_run(caller_app_id, app_id);
+                       if (ret != DATA_CONTROL_ERROR_NONE) {
+                               bundle_free(send_data);
+                               _socket_info_free((gpointer)socket_info);
+                               free(socket_hash_key);
+                               return ret;
+                       }
+
                        g_hash_table_insert(__socket_pair_hash,
                                        socket_hash_key, socket_info);
                }
index 79561f4..1ca7270 100755 (executable)
@@ -264,12 +264,12 @@ static int __noti_request_appsvc_run(const char *callee_id,
        bundle_add_str(arg_list, AUL_K_DATA_CONTROL_TYPE, "CORE");
 
        pid = appsvc_run_service(arg_list, 0, NULL, NULL);
+       bundle_free(arg_list);
+
        if (pid >= 0) {
                _LOGI("Launch the provider app successfully: %d", pid);
-               bundle_free(arg_list);
        } else if (pid == APPSVC_RET_EINVAL) {
                _LOGE("not able to launch service: %d", pid);
-               bundle_free(arg_list);
                return DATA_CONTROL_ERROR_INVALID_PARAMETER;
        } else {
                _LOGE("unable to launch service: %d", pid);
@@ -416,18 +416,6 @@ EXPORT_API int data_control_add_data_change_cb(
                goto err;
        }
 
-       cb_info = (changed_cb_info_s *)calloc(1,
-                       sizeof(changed_cb_info_s));
-       if (cb_info == NULL) {
-               _LOGE("changed_cb_info_s alloc fail out of memory.");
-               ret = DATA_CONTROL_ERROR_OUT_OF_MEMORY;
-               goto err;
-       }
-
-       cb_info->changed_cb = callback;
-       cb_info->user_data = user_data;
-       cb_info->callback_id = data_changed_callback_id;
-
        result_cb_info =
                (add_callback_result_cb_info_s *)calloc(1, sizeof(add_callback_result_cb_info_s));
        if (result_cb_info == NULL) {
@@ -452,8 +440,20 @@ EXPORT_API int data_control_add_data_change_cb(
                goto err;
        }
 
+       cb_info = (changed_cb_info_s *)calloc(1, sizeof(changed_cb_info_s));
+       if (cb_info == NULL) {
+               _LOGE("changed_cb_info_s alloc fail out of memory.");
+               ret = DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               goto err;
+       }
+
+       cb_info->changed_cb = callback;
+       cb_info->user_data = user_data;
+       cb_info->callback_id = data_changed_callback_id;
+
        provider_info->cb_list = g_list_append(
                        provider_info->cb_list, cb_info);
+
        *callback_id = data_changed_callback_id;
 
        result_cb_info->timeout_id =