aboutsummaryrefslogtreecommitdiff
path: root/http.c
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-07-20 23:52:52 +0200
commit4bcf440bf28dbca10e3c07690f1c153728652f74 (patch)
treeecf824f1c962cfca5b0578ce6370450195280075 /http.c
parentfbaa7b9bcf0b3cfe1f086e72c12214db477cebdd (diff)
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.
Diffstat (limited to 'http.c')
-rw-r--r--http.c15
1 files changed, 10 insertions, 5 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);