From: Vitaliy Cherepanov Date: Tue, 27 Dec 2016 08:08:26 +0000 (+0300) Subject: Fix memleak in add_binary and remove_binary X-Git-Tag: submit/tizen_3.0/20161228.101250^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49ea70b750c24a48f9d4d6469d85341454ab3078;p=platform%2Fcore%2Fsystem%2Fswap-probe.git Fix memleak in add_binary and remove_binary Change-Id: I5ffe57492cfd6cf6b8117c9d80bac298191d51f0 Signed-off-by: Vitaliy Cherepanov Signed-off-by: Dmitry Kovalenko --- diff --git a/helper/dahelper.c b/helper/dahelper.c index 74861d9..caa2183 100755 --- a/helper/dahelper.c +++ b/helper/dahelper.c @@ -195,18 +195,24 @@ int add_binary(char *path) if (!SLIST_EMPTY(&gTraceInfo.bins_info.bins_list) && (_find_binary_no_lock(real_path) != NULL)) { ret = -EALREADY; - goto add_bin_unlock; + goto free_real_path; } bin_info = malloc(sizeof(*bin_info)); if (bin_info == NULL) { ret = -ENOMEM; - goto add_bin_unlock; + goto free_real_path; } /* TODO Slow copy / cleanup of memory allocated somewhere else? */ bin_info->path = real_path; SLIST_INSERT_HEAD(&gTraceInfo.bins_info.bins_list, bin_info, list); + /* Success */ + goto add_bin_unlock; + +free_real_path: + /* Something went wrong */ + free(real_path); add_bin_unlock: pthread_mutex_unlock(&gTraceInfo.bins_info.bins_mutex); @@ -241,9 +247,12 @@ int remove_binary(char *path) } SLIST_REMOVE(&gTraceInfo.bins_info.bins_list, bin_info, bin_info_t, list); + free(bin_info->path); + free(bin_info); remove_bin_unlock: pthread_mutex_unlock(&gTraceInfo.bins_info.bins_mutex); + free(real_path); return ret; }