From 0fd00ef40e406cd5875612e13bb40d7ec6b75310 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Fri, 31 Jan 2020 13:53:57 +0900 Subject: [PATCH] Fix memory leak WGID-427792 Change-Id: I8788932658bc5b65f94354c7c9c33c76c6bba288 --- src/tethering.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tethering.c b/src/tethering.c index 54da6f1..c532fa0 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -3398,12 +3398,6 @@ static int __add_mac_to_file(const char *filepath, const char *mac) bool mac_exist = false; char *p_mac = NULL; - p_mac = strdup(mac); - if (p_mac == NULL) { - ERR("strdup failed\n"); //LCOV_EXCL_LINE - return TETHERING_ERROR_OUT_OF_MEMORY; - } - fp = fopen(filepath, "a+"); if (!fp) { ERR("fopen is failed\n"); //LCOV_EXCL_LINE @@ -3419,12 +3413,21 @@ static int __add_mac_to_file(const char *filepath, const char *mac) } if (!mac_exist) { + p_mac = strdup(mac); + if (p_mac == NULL) { + ERR("strdup failed\n"); //LCOV_EXCL_LINE + fclose(fp); + return TETHERING_ERROR_OUT_OF_MEMORY; + } + fprintf(fp, "%s\n", mac); if ((strcmp(filepath, ALLOWED_LIST) == 0)) allowed_list = g_slist_append(allowed_list, p_mac); else if ((strcmp(filepath, BLOCKED_LIST) == 0)) blocked_list = g_slist_append(blocked_list, p_mac); + else + free(p_mac); } fclose(fp); -- 2.7.4