aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-08 18:02:36 +0100
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-03-08 18:17:32 +0100
commite37a0248e865db2d69c89d5c7bd8651dae255cab (patch)
treec5b2485c885aa55b527921bc0cda2de3dbe90d03
parent6cbab96869cbee4c7d6fed95d30221903c616aa5 (diff)
downloadslcl-e37a0248e865db2d69c89d5c7bd8651dae255cab.tar.gz
Remove(3) f->tmpname from ctx_free
Until now, f->tmpname was removed by move_file when the move operation succeeded. However, since a HTTP operation can fail before move_file is called, the temporary file must also be removed.
-rw-r--r--http.c15
-rw-r--r--main.c5
2 files changed, 10 insertions, 10 deletions
diff --git a/http.c b/http.c
index a06f29d..cbef2bc 100644
--- a/http.c
+++ b/http.c
@@ -225,21 +225,26 @@ static void ctx_free(struct ctx *const c)
free(m->files);
free(m->boundary);
+ if (m->fd >= 0 && close(m->fd))
+ fprintf(stderr, "%s: close(2) m->fd: %s\n",
+ __func__, strerror(errno));
+
for (size_t i = 0; i < m->nforms; i++)
{
struct form *const f = &m->forms[i];
free(f->name);
free(f->filename);
- free(f->tmpname);
free(f->value);
+
+ if (f->tmpname && remove(f->tmpname) && errno != ENOENT)
+ fprintf(stderr, "%s: remove(3) %s: %s\n",
+ __func__, f->tmpname, strerror(errno));
+
+ free(f->tmpname);
}
free(m->forms);
-
- if (m->fd >= 0 && close(m->fd))
- fprintf(stderr, "%s: close(2) m->fd: %s\n",
- __func__, strerror(errno));
}
free(c->field);
diff --git a/main.c b/main.c
index 7b8f463..2256fe7 100644
--- a/main.c
+++ b/main.c
@@ -638,11 +638,6 @@ end:
fprintf(stderr, "%s: fclose(3): %s\n", __func__, strerror(errno));
ret = -1;
}
- else if (remove(old))
- {
- fprintf(stderr, "%s: remove(3): %s\n", __func__, strerror(errno));
- ret = -1;
- }
return ret;
}