nvram: fix memory leak
[openwrt/openwrt.git] / package / utils / nvram / src / cli.c
index 488d641cfcfef49751dd94c2481d3617d5eb6cfb..4f9c77804d793df4839fdd650f37f09fe9ee21fa 100644 (file)
 
 static nvram_handle_t * nvram_open_rdonly(void)
 {
-       const char *file = nvram_find_staging();
+       char *file = nvram_find_staging();
 
        if( file == NULL )
                file = nvram_find_mtd();
 
-       if( file != NULL )
-               return nvram_open(file, NVRAM_RO);
+       if( file != NULL ) {
+               nvram_handle_t *h = nvram_open(file, NVRAM_RO);
+               if( strcmp(file, NVRAM_STAGING) )
+                       free(file);
+               return h;
+       }
 
        return NULL;
 }