Fix memory leak 03/110903/2 accepted/tizen/common/20170125.113341 accepted/tizen/ivi/20170125.090314 accepted/tizen/mobile/20170125.090223 accepted/tizen/tv/20170125.090239 accepted/tizen/unified/20170309.040001 accepted/tizen/wearable/20170125.090256 submit/tizen/20170125.053826 submit/tizen_unified/20170308.100414
authorSaurav Babu <saurav.babu@samsung.com>
Wed, 18 Jan 2017 12:22:36 +0000 (17:52 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Thu, 19 Jan 2017 03:58:04 +0000 (09:28 +0530)
Change-Id: I2fb5fb4d12fcac486a4b6994ee9fe14a37de1513
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
lib/route/pktloc.c

index f0d0155..99e51d3 100644 (file)
@@ -90,12 +90,16 @@ static int read_pktlocs(void)
        /* if stat fails, just try to read the file */
        if (stat(path, &st) == 0) {
                /* Don't re-read file if file is unchanged */
-               if (last_read == st.st_mtime)
-                       return 0;
+               if (last_read == st.st_mtime) {
+                       err = 0;
+                       goto errout;
+               }
        }
 
-       if (!(fd = fopen(path, "r")))
-               return -NLE_PKTLOC_FILE;
+       if (!(fd = fopen(path, "r"))) {
+               err = -NLE_PKTLOC_FILE;
+               goto errout;
+       }
 
        for (i = 0; i < PKTLOC_NAME_HT_SIZ; i++) {
                struct rtnl_pktloc *loc, *n;
@@ -106,22 +110,30 @@ static int read_pktlocs(void)
                nl_init_list_head(&pktloc_name_ht[i]);
        }
 
-       if ((err = pktloc_lex_init(&scanner)) < 0)
-               return -NLE_FAILURE;
+       if ((err = pktloc_lex_init(&scanner)) < 0) {
+               err = -NLE_FAILURE;
+               goto errout_close;
+       }
 
        buf = pktloc__create_buffer(fd, YY_BUF_SIZE, scanner);
        pktloc__switch_to_buffer(buf, scanner);
 
-       if ((err = pktloc_parse(scanner)) < 0)
-               return -NLE_FAILURE;
+       if ((err = pktloc_parse(scanner)) < 0) {
+               err = -NLE_FAILURE;
+               goto errout_scanner;
+       }
 
+       last_read = st.st_mtime;
+
+errout_scanner:
        if (scanner)
                pktloc_lex_destroy(scanner);
-
+errout_close:
+       fclose(fd);
+errout:
        free(path);
-       last_read = st.st_mtime;
 
-       return 0;
+       return err;
 }
 
 /**
@@ -163,6 +175,6 @@ static int __init pktloc_init(void)
 
        for (i = 0; i < PKTLOC_NAME_HT_SIZ; i++)
                nl_init_list_head(&pktloc_name_ht[i]);
-       
+
        return 0;
 }