[hackers] [quark] fix memory leak in sendfile() || Hiltjo Posthuma
commit 3efce07af97a5311853db105a0140033694bcd45
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Tue Jun 27 21:39:24 2017 +0200
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Jun 27 23:31:08 2017 +0200
fix memory leak in sendfile()
FILE *fp is not closed.
diff --git a/quark.c b/quark.c
index f5fc6b0..d2ae1f1 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -407,12 +407,14 @@ sendfile(int fd, char *name, struct request *r, struct stat *st, char *mime,
/* open file */
if (!(fp = fopen(name, "r"))) {
- return sendstatus(fd, S_FORBIDDEN);
+ s = sendstatus(fd, S_FORBIDDEN);
+ goto cleanup;
}
/* seek to lower bound */
if (fseek(fp, lower, SEEK_SET)) {
- return sendstatus(fd, S_INTERNAL_SERVER_ERROR);
+ s = sendstatus(fd, S_INTERNAL_SERVER_ERROR);
+ goto cleanup;
}
/* send header as late as possible */
_AT_@ -428,16 +430,19 @@ sendfile(int fd, char *name, struct request *r, struct stat *st, char *mime,
"Content-Length: %zu\r\n",
s, status_str[s], timestamp(0, t1),
timestamp(st->st_mtim.tv_sec, t2), mime, upper - lower) < 0) {
- return S_REQUEST_TIMEOUT;
+ s = S_REQUEST_TIMEOUT;
+ goto cleanup;
}
if (range) {
if (dprintf(fd, "Content-Range: bytes %zu-%zu/%zu\r\n",
lower, upper - 1, st->st_size) < 0) {
- return S_REQUEST_TIMEOUT;
+ s = S_REQUEST_TIMEOUT;
+ goto cleanup;
}
}
if (dprintf(fd, "\r\n") < 0) {
- return S_REQUEST_TIMEOUT;
+ s = S_REQUEST_TIMEOUT;
+ goto cleanup;
}
if (r->method == M_GET) {
_AT_@ -460,6 +465,9 @@ sendfile(int fd, char *name, struct request *r, struct stat *st, char *mime,
}
}
}
+cleanup:
+ if (fp)
+ fclose(fp);
return s;
}
Received on Tue Jun 27 2017 - 23:31:28 CEST
This archive was generated by hypermail 2.3.0
: Tue Jun 27 2017 - 23:36:42 CEST