diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-08-22 02:18:14 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-08-22 02:27:33 +0200 |
| commit | 15686de86f15866041107bd9830834636008fe1b (patch) | |
| tree | 899dcde0ed6930085452dd508198dc4791afd929 | |
| parent | 407b5d32156d60420f83d6e0567e9b3e9c878ad9 (diff) | |
http.c: Fix memory leak on read failure
For some unknown reason, ctx_free was only called by update_lstate, but
this is not the only function that modifies a struct ctx instance. Since
struct ctx is related to read operations, ctx_free must instead be
called whenever http_read fails.
| -rw-r--r-- | http.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1316,7 +1316,6 @@ static int update_lstate(struct http_ctx *const h, bool *const close, int (*const f)(struct http_ctx *), const char *const buf, size_t *const sz) { - int ret = 1; struct ctx *const c = &h->ctx; const char b = *buf; @@ -1330,7 +1329,7 @@ static int update_lstate(struct http_ctx *const h, bool *const close, else { fprintf(stderr, "%s: line too long\n", __func__); - goto failure; + return 1; } break; @@ -1340,8 +1339,10 @@ static int update_lstate(struct http_ctx *const h, bool *const close, { h->line[c->len] = '\0'; - if ((ret = f(h))) - goto failure; + const int ret = f(h); + + if (ret) + return ret; c->len = 0; } @@ -1353,7 +1354,7 @@ static int update_lstate(struct http_ctx *const h, bool *const close, else { fprintf(stderr, "%s: line too long\n", __func__); - goto failure; + return 1; } c->lstate = LINE_CR; @@ -1362,10 +1363,6 @@ static int update_lstate(struct http_ctx *const h, bool *const close, (*sz)--; return 0; - -failure: - ctx_free(c); - return ret; } static int start_boundary_line(struct http_ctx *const h) @@ -2188,7 +2185,10 @@ int http_read(struct http_ctx *const h, bool *const close) const int ret = read_buf(h, close, &buf[r - rem], &rem); if (ret) + { + ctx_free(&h->ctx); return ret; + } } return 0; |
