file: fix memleak on mktemp() errors
authorFelix Fietkau <nbd@openwrt.org>
Thu, 24 Oct 2013 21:24:32 +0000 (23:24 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 24 Oct 2013 21:24:32 +0000 (23:24 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
file.c

diff --git a/file.c b/file.c
index 509ed73..44b2e02 100644 (file)
--- a/file.c
+++ b/file.c
@@ -703,8 +703,10 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
                UCI_THROW(ctx, UCI_ERR_MEM);
 
        mktemp(filename);
                UCI_THROW(ctx, UCI_ERR_MEM);
 
        mktemp(filename);
-       if (!*filename)
+       if (!*filename) {
+               free(filename);
                UCI_THROW(ctx, UCI_ERR_IO);
                UCI_THROW(ctx, UCI_ERR_IO);
+       }
 
        if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
                UCI_THROW(ctx, UCI_ERR_IO);
 
        if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
                UCI_THROW(ctx, UCI_ERR_IO);