summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseungha.son <seungha.son@samsung.com>2017-03-22 16:32:42 +0900
committerjusung son <jusung07.son@samsung.com>2017-03-28 14:31:54 +0900
commit88f24f22fe195072597c2baa48347f58de41d815 (patch)
tree04312400d7e415b36d2292aaed55615991879d3e
parentfbf2d7b7431a2d51526a3eaeecb30b974300ae67 (diff)
downloadnotification-88f24f22fe195072597c2baa48347f58de41d815.tar.gz
notification-88f24f22fe195072597c2baa48347f58de41d815.tar.bz2
notification-88f24f22fe195072597c2baa48347f58de41d815.zip
Fix Memory Leak
Signed-off-by: seungha.son <seungha.son@samsung.com> Change-Id: Idcd8ca903456b13e15f5c7e150296c19e5a6af02 Signed-off-by: jusung son <jusung07.son@samsung.com>
-rwxr-xr-xsrc/notification_ipc.c52
-rwxr-xr-xsrc/notification_setting.c2
2 files changed, 25 insertions, 29 deletions
diff --git a/src/notification_ipc.c b/src/notification_ipc.c
index f97dd7d..4b66215 100755
--- a/src/notification_ipc.c
+++ b/src/notification_ipc.c
@@ -1358,15 +1358,13 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h *
{
int result;
int count;
- int index = 0;
GDBusMessage *reply = NULL;
- GVariant *setting_body;
- GVariant *reply_body;
- GVariant *iter_body;
- GVariantIter *iter;
- notification_system_setting_h result_setting;
+ GVariant *setting_body = NULL;
+ GVariant *reply_body = NULL;
+ GVariant *iter_body = NULL;
+ GVariantIter *iter = NULL;
+ notification_system_setting_h result_setting = NULL;
dnd_allow_exception_h dnd_allow_exception;
- dnd_allow_exception_h temp;
result = _dbus_init();
if (result != NOTIFICATION_ERROR_NONE) {
@@ -1379,43 +1377,41 @@ int notification_ipc_request_load_system_setting(notification_system_setting_h *
reply_body = g_dbus_message_get_body(reply);
g_variant_get(reply_body, "(v)", &setting_body);
- result_setting = (struct notification_system_setting *)malloc(sizeof(struct notification_system_setting));
+ result_setting = (struct notification_system_setting *)calloc(1, sizeof(struct notification_system_setting));
if (result_setting == NULL) {
NOTIFICATION_ERR("malloc failed");
- g_object_unref(reply);
- return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
}
notification_ipc_make_system_setting_from_gvariant(result_setting, setting_body);
- result_setting->dnd_allow_exceptions = NULL;
result = _send_sync_noti(g_variant_new("(i)", uid), &reply, "load_dnd_allow_exception");
if (result == NOTIFICATION_ERROR_NONE) {
reply_body = g_dbus_message_get_body(reply);
g_variant_get(reply_body, "(ia(v))", &count, &iter);
- dnd_allow_exception = (dnd_allow_exception_h)malloc(sizeof(struct notification_system_setting_dnd_allow_exception) * count);
- if (dnd_allow_exception == NULL) {
- g_object_unref(reply);
- g_variant_iter_free(iter);
- free(result_setting);
- return NOTIFICATION_ERROR_OUT_OF_MEMORY;
- }
-
while (g_variant_iter_loop(iter, "(v)", &iter_body)) {
- temp = dnd_allow_exception + index;
-
- notification_ipc_make_dnd_allow_exception_from_gvariant(temp, iter_body);
- result_setting->dnd_allow_exceptions = g_list_append(result_setting->dnd_allow_exceptions, temp);
- index++;
+ dnd_allow_exception = (dnd_allow_exception_h)calloc(1, sizeof(struct notification_system_setting_dnd_allow_exception));
+ if (dnd_allow_exception == NULL) {
+ result = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ notification_ipc_make_dnd_allow_exception_from_gvariant(dnd_allow_exception, iter_body);
+ result_setting->dnd_allow_exceptions = g_list_append(result_setting->dnd_allow_exceptions, dnd_allow_exception);
}
+ *setting = result_setting;
}
-
- *setting = result_setting;
- g_variant_unref(setting_body);
- g_variant_iter_free(iter);
}
+out:
+ if (result != NOTIFICATION_ERROR_NONE && result_setting)
+ notification_system_setting_free_system_setting(result_setting);
+ if (iter)
+ g_variant_iter_free(iter);
+ if (setting_body)
+ g_variant_unref(setting_body);
if (reply)
g_object_unref(reply);
diff --git a/src/notification_setting.c b/src/notification_setting.c
index 1cb6d4d..5ff0fad 100755
--- a/src/notification_setting.c
+++ b/src/notification_setting.c
@@ -671,7 +671,7 @@ EXPORT_API int notification_system_setting_free_system_setting(notification_syst
/* add codes to free all properties */
if (system_setting->dnd_allow_exceptions != NULL)
- g_list_free(system_setting->dnd_allow_exceptions);
+ g_list_free_full(system_setting->dnd_allow_exceptions, free);
SAFE_FREE(system_setting);