diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-10-08 01:59:05 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-10-08 02:03:17 +0200 |
| commit | 805630dbfcd409a5d49bc89102f4183b71f713f9 (patch) | |
| tree | 96df02d2e1ed191380556ca56e415b9e4badbbad /main.c | |
| parent | 9542016d5d820eef0882ed7f4c3da5f238453707 (diff) | |
| download | slcl-805630dbfcd409a5d49bc89102f4183b71f713f9.tar.gz | |
Use free function pointer for chunk/step
libweb now supports deallocating user-defined data whenever an error
occurs during a chunked transfer or an asynchronous HTTP response, thus
avoiding memory leaks.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -711,8 +711,10 @@ failure: return -1; } -static void free_search(struct search *const s) +static void free_search(void *const p) { + struct search *const s = p; + if (!s) return; @@ -735,7 +737,7 @@ static int search_step(const struct http_payload *const p, if (page_search(r, &s->search)) { fprintf(stderr, "%s: page_search failed\n", __func__); - goto failure; + return -1; } free_search(s); @@ -743,17 +745,13 @@ static int search_step(const struct http_payload *const p, case CFTW_FATAL: fprintf(stderr, "%s: cftw_step failed\n", __func__); - goto failure; + return -1; case CFTW_AGAIN: break; } return 0; - -failure: - free_search(s); - return -1; } static int search(const struct http_payload *const p, @@ -822,7 +820,8 @@ static int search(const struct http_payload *const p, *r = (const struct http_response) { .step.payload = search_step, - .args = s + .args = s, + .free = free_search }; s->search.root = s->root.str; |
