From 2a89a332f97db1b3f6673c7ce8eb9a79d562238b Mon Sep 17 00:00:00 2001 From: Seungha Son Date: Wed, 24 Jan 2018 17:15:54 +0900 Subject: [PATCH] Fix memory leak Signed-off-by: Seungha Son Change-Id: I3ea07e9acaa4e3669a848c1256e94b931f67ea1d Signed-off-by: jusung son --- src/notification_ipc.c | 16 ++++++++-------- src/notification_shared_file.c | 16 +++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/notification_ipc.c b/src/notification_ipc.c index 9abf88e..3439767 100755 --- a/src/notification_ipc.c +++ b/src/notification_ipc.c @@ -365,7 +365,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; @@ -386,13 +386,13 @@ static void _add_noti_notify(GVariant *parameters) /* Enable changed cb */ noti_op = _ipc_create_op(NOTIFICATION_OP_INSERT, 1, &(noti->priv_id), 1, ¬i); 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 */ @@ -401,7 +401,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; @@ -417,13 +417,13 @@ static void _update_noti_notify(GVariant *parameters) noti_op = _ipc_create_op(NOTIFICATION_OP_UPDATE, 1, &(noti->priv_id), 1, ¬i); 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 */ diff --git a/src/notification_shared_file.c b/src/notification_shared_file.c index 45367c6..84bb881 100755 --- a/src/notification_shared_file.c +++ b/src/notification_shared_file.c @@ -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)) { @@ -795,6 +795,7 @@ int __set_sharing_for_new_target(sharing_req_data_s *req_data, app_info = strdup(target_info->app_id); if (app_info == NULL) { ERR("out of memory"); + ret = NOTIFICATION_ERROR_OUT_OF_MEMORY; goto out; } @@ -853,6 +854,9 @@ 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 +969,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 +979,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,7 +1001,7 @@ 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); + req_data->dir = __get_shared_dir(noti); __OOM_CHECK(req_data->dir, NOTIFICATION_ERROR_OUT_OF_MEMORY, __free_req_info(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); -- 2.7.4