Fix memory leak 90/223590/2 accepted/tizen/unified/20200205.125337 submit/tizen/20200204.080737
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 31 Jan 2020 04:53:57 +0000 (13:53 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 31 Jan 2020 06:43:33 +0000 (15:43 +0900)
WGID-427792

Change-Id: I8788932658bc5b65f94354c7c9c33c76c6bba288

src/tethering.c

index 54da6f1..c532fa0 100755 (executable)
@@ -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);