From a0df51ec008ca9966998aedf713a51992ffb725b Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Wed, 15 Jun 2016 16:44:22 +0900 Subject: [PATCH] fix memory leak Change-Id: I8e11dbe0b607debebf43169e12d2c5bfd8b2324f Signed-off-by: Jiwoong Im --- alarm-manager.c | 26 +++++++++++++++++++++++--- alarm-session-agent/agent.c | 21 ++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/alarm-manager.c b/alarm-manager.c index d068393..39d71a9 100644 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -1155,30 +1155,50 @@ static gboolean __send_noti_to_session_bus(char *service_name, ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { ALARM_MGR_EXCEPTION_PRINT("connect failed - (errno %d)", errno); + close(fd); return FALSE; } gv = g_variant_new("(is)", alarm_id, service_name); + if (!gv) { + close(fd); + return FALSE; + } + len = g_variant_get_size(gv); - gv_data = malloc(len); - if (!gv_data) + gv_data = NULL; + if (len > 0) + gv_data = malloc(len); + + if (!gv_data) { + g_variant_unref(gv); + close(fd); return FALSE; + } g_variant_store(gv, gv_data); + g_variant_unref(gv); data = malloc(len + 4); + if (!data) { + close(fd); + return FALSE; + } memcpy(data, &len, 4); memcpy(data + 4, gv_data, len); + free(gv_data); if (send(fd, data, len + 4, 0) == -1) { ALARM_MGR_EXCEPTION_PRINT("sendto() failed (errno %d)", errno); + free(data); + close(fd); return FALSE; } + free(data); close(fd); - return TRUE; } diff --git a/alarm-session-agent/agent.c b/alarm-session-agent/agent.c index 0a59824..39f93c0 100644 --- a/alarm-session-agent/agent.c +++ b/alarm-session-agent/agent.c @@ -194,12 +194,19 @@ static gboolean _alarm_agent_main(gint fd, GIOCondition condition, if (errno != EAGAIN && errno != EINTR) LOGE("recv: fd %d errno %d", clifd, errno); } + close(clifd); + return G_SOURCE_CONTINUE; + } + + if (len <= 0) { + close(clifd); return G_SOURCE_CONTINUE; } data = malloc(len); if (!data) { flush_data(clifd, len); + close(clifd); return G_SOURCE_CONTINUE; } @@ -211,18 +218,26 @@ static gboolean _alarm_agent_main(gint fd, GIOCondition condition, if (errno != EAGAIN && errno != EINTR) LOGE("recv: fd %d errno %d", clifd, errno); } - free(data); + close(clifd); return G_SOURCE_CONTINUE; } gv = g_variant_new_from_data(G_VARIANT_TYPE("(is)"), data, len, TRUE, NULL, NULL); - assert(gv); - g_variant_get(gv, "(i&s)", &alarm_id, &service_name); + if (!gv) { + free(data); + close(clifd); + return G_SOURCE_CONTINUE; + } + + g_variant_get(gv, "(i&s)", &alarm_id, &service_name); _send_noti(service_name, alarm_id); + + free(data); + g_variant_unref(gv); close(clifd); return G_SOURCE_CONTINUE; } -- 2.7.4