Fix resource leaks 37/196737/2
authormk5004.lee <mk5004.lee@samsung.com>
Fri, 4 Jan 2019 04:15:26 +0000 (13:15 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Fri, 4 Jan 2019 05:28:07 +0000 (14:28 +0900)
Change-Id: I625d2dd3046819f827b208ef4259b9187768ae78
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
src/notification.c
src/notification_internal.c
src/notification_ipc.c
src/notification_noti.c
src/notification_shared_file.c

index 6b22208c26566521a0d04a5232450618b2c28bc7..4a296d198279c9096197923f5211eb6b4ebcdca0 100755 (executable)
@@ -140,6 +140,10 @@ EXPORT_API int notification_set_image(notification_h noti,
                bundle_add_str(priv_b, buf_key, priv_path);
                noti->b_priv_image_path = priv_b;
        }
+
+       if (priv_path)
+               free(priv_path);
+
        return NOTIFICATION_ERROR_NONE;
 }
 
index 562e0bf5df9fd2b8f265b432ffcbec8075058726..906aabf74f507880a7eabb364b5165b967f4f51a 100755 (executable)
@@ -1689,7 +1689,7 @@ EXPORT_API int notification_post_with_event_cb_for_uid(notification_h noti, even
                info->cb = cb;
                info->userdata = userdata;
        } else {
-               info = (notification_event_cb_info_s *)malloc(sizeof(notification_cb_info_s));
+               info = (notification_event_cb_info_s *)malloc(sizeof(notification_event_cb_info_s));
                if (info == NULL) {
                        /* LCOV_EXCL_START */
                        NOTIFICATION_ERR("Failed to alloc memory");
index 8b9a8272669d399f5521d09bed90ecc2d3829f06..77c1f4540be1c77bfa1da94b875f56b388015949 100755 (executable)
@@ -376,7 +376,7 @@ static void _add_noti_notify(GVariant *parameters)
 {
        int ret;
        notification_h noti;
-       notification_op *noti_op;
+       notification_op *noti_op = NULL;
        GVariant *body = NULL;
        uid_t uid;
 
@@ -397,13 +397,13 @@ static void _add_noti_notify(GVariant *parameters)
                /* Enable changed cb */
                noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, &noti);
                ret = notification_get_uid(noti, &uid);
-               if (noti_op != NULL && ret == NOTIFICATION_ERROR_NONE) {
+               if (noti_op != NULL && ret == NOTIFICATION_ERROR_NONE)
                        notification_call_changed_cb_for_uid(noti_op, 1, uid);
-                       free(noti_op);
-               }
        }
        g_variant_unref(body);
        notification_free(noti);
+       if (noti_op)
+               free(noti_op);
 }
 /* LCOV_EXCL_STOP */
 
@@ -412,7 +412,7 @@ static void _update_noti_notify(GVariant *parameters)
 {
        int ret;
        notification_h noti;
-       notification_op *noti_op;
+       notification_op *noti_op = NULL;
        GVariant *body = NULL;
        uid_t uid;
 
@@ -428,13 +428,13 @@ static void _update_noti_notify(GVariant *parameters)
 
        noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, &noti);
        ret = notification_get_uid(noti, &uid);
-       if (noti_op != NULL && ret == NOTIFICATION_ERROR_NONE) {
+       if (noti_op != NULL && ret == NOTIFICATION_ERROR_NONE)
                notification_call_changed_cb_for_uid(noti_op, 1, uid);
-               free(noti_op);
-       }
 
        g_variant_unref(body);
        notification_free(noti);
+       if (noti_op)
+               free(noti_op);
 }
 /* LCOV_EXCL_STOP */
 
index 6d36e0a8fb489514bfdcba4d79e20b11704ecf75..87ac2005244e02dd90e1b6937cc79c6a92a063c6 100755 (executable)
@@ -963,6 +963,7 @@ static int _check_text_input(notification_h noti)
                        NOTIFICATION_ERR("Event handler for text_input is not set");
                        return -1;
                }
+               app_control_destroy(app_control);
        }
 
        return NOTIFICATION_ERROR_NONE;
index 9bf91e6664bc68591a4c8bef9ab52e7988dcde7d..cf44970ec8e5638c332729edcfcfa0a0183282f1 100755 (executable)
@@ -782,7 +782,7 @@ int __set_sharing_for_new_target(sharing_req_data_s *req_data,
        private_sharing_req *handle = NULL;
        GList *iter, *tmp;
        target_app_info_s *target_info;
-       char *app_info;
+       char *app_info = NULL;
 
        iter = target_app_list;
        for (; iter != NULL; iter = g_list_next(iter)) {
@@ -853,6 +853,8 @@ int __set_sharing_for_new_target(sharing_req_data_s *req_data,
        }
 
 out:
+       if (ret != NOTIFICATION_ERROR_NONE && app_info)
+               free(app_info);
        if (handle != NULL)
                security_manager_private_sharing_req_free(handle);
        if (path_array != NULL)
@@ -965,7 +967,6 @@ EXPORT_API int notification_set_private_sharing(notification_h noti,
                                                uid_t uid)
 {
        int ret = NOTIFICATION_ERROR_NONE;
-       char *shared_dir;
        bool is_overlapping = false;
        sharing_req_data_s *req_data;
        sharing_file_info_s *file_info, *dup_file_info;
@@ -976,10 +977,6 @@ EXPORT_API int notification_set_private_sharing(notification_h noti,
        if (noti == NULL || noti->caller_app_id == NULL)
                return NOTIFICATION_ERROR_INVALID_PARAMETER;
 
-       shared_dir = __get_shared_dir(noti);
-       if (shared_dir == NULL)
-               return NOTIFICATION_ERROR_NONE;
-
        tmp = g_list_find_custom(__uid_list, GINT_TO_POINTER(uid),
                                                __comp_uid_info_list);
        if (tmp == NULL) {
@@ -1002,9 +999,11 @@ EXPORT_API int notification_set_private_sharing(notification_h noti,
                __OOM_CHECK(req_data->app_id, NOTIFICATION_ERROR_OUT_OF_MEMORY,
                                                __free_req_info(req_data));
 
-               req_data->dir = strdup(shared_dir);
-               __OOM_CHECK(req_data->dir, NOTIFICATION_ERROR_OUT_OF_MEMORY,
-                                               __free_req_info(req_data));
+               req_data->dir = __get_shared_dir(noti);
+               if (req_data->dir == NULL) {
+                       __free_req_info(req_data);
+                       return NOTIFICATION_ERROR_INVALID_PARAMETER;
+               }
 
                uid_info->sharing_req_list = g_list_append(
                        uid_info->sharing_req_list, req_data);
@@ -1012,8 +1011,7 @@ EXPORT_API int notification_set_private_sharing(notification_h noti,
                req_data = (sharing_req_data_s *)req_list->data;
        }
 
-       __make_sharing_dir(shared_dir);
-       free(shared_dir);
+       __make_sharing_dir(req_data->dir);
 
        tmp = g_list_find_custom(req_data->priv_id_list,
                                GINT_TO_POINTER(noti->priv_id), __comp_priv_id);