From: Krzysztof Kuznik <k.kuz...@avsystem.com>

In file file.c function uci_file_load() allocates memory for filename.
When uci_open_stream() failed with exception this memory was never freed.
This patch makes call to uci_open_stream() wrapped in exception handling
inside uci_file_load() where filename is freed.

Signed-off-by: Krzysztof Kuznik <k.kuz...@avsystem.com>
---
diff --git a/file.c b/file.c
index c2b0e72..e86643b 100644
--- a/file.c
+++ b/file.c
@@ -834,9 +834,9 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na
         break;
     }

+    UCI_TRAP_SAVE(ctx, done);
     file = uci_open_stream(ctx, filename, SEEK_SET, false, false);
     ctx->err = 0;
-    UCI_TRAP_SAVE(ctx, done);
     UCI_INTERNAL(uci_import, ctx, file, name, &package, true);
     UCI_TRAP_RESTORE(ctx);

@@ -848,8 +848,10 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na

 done:
     uci_close_stream(file);
-    if (ctx->err)
+    if (ctx->err) {
+        free(filename);
         UCI_THROW(ctx, ctx->err);
+    }
     return package;
 }

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to