X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=file.c;h=36bfdda7272dbb4409442932158293436c345da2;hp=f7061dfc7f6831403d80ff96783577cce0d8ecdc;hb=be457b5263f1f0504e50c241c18e21bb340cef7e;hpb=42429219a90d697d88c5203bddef34c31e552643 diff --git a/file.c b/file.c index f7061df..36bfdda 100644 --- a/file.c +++ b/file.c @@ -702,9 +702,13 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag if ((asprintf(&filename, "%s/.%s.uci-XXXXXX", ctx->confdir, p->e.name) < 0) || !filename) UCI_THROW(ctx, UCI_ERR_MEM); - mktemp(filename); - if (!*filename) + if (!mktemp(filename)) + *filename = 0; + + 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); @@ -755,10 +759,8 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag UCI_TRAP_RESTORE(ctx); done: - if (name) - free(name); - if (path) - free(path); + free(name); + free(path); uci_close_stream(f1); if (do_rename && rename(filename, p->path)) { unlink(filename);