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);
/* open the config file for writing now, so that it is locked */
- f1 = uci_open_stream(ctx, p->path, SEEK_SET, false, false);
+ f1 = uci_open_stream(ctx, p->path, SEEK_SET, true, true);
/* flush unsaved changes and reload from delta file */
UCI_TRAP_SAVE(ctx, done);