file: fix memleak on mktemp() errors
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 509ed73be0ccd00deb52606293c7855e754cfe5a..44b2e0232cac0dc592301c010e792aba65d12674 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);
-       if (!*filename)
+       if (!*filename) {
+               free(filename);
                UCI_THROW(ctx, UCI_ERR_IO);
+       }
 
        if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
                UCI_THROW(ctx, UCI_ERR_IO);