aboutsummaryrefslogtreecommitdiff
path: root/zip.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-10-08 01:59:05 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-10-08 02:03:17 +0200
commit805630dbfcd409a5d49bc89102f4183b71f713f9 (patch)
tree96df02d2e1ed191380556ca56e415b9e4badbbad /zip.c
parent9542016d5d820eef0882ed7f4c3da5f238453707 (diff)
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 'zip.c')
-rw-r--r--zip.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/zip.c b/zip.c
index 704bf36..7e12c73 100644
--- a/zip.c
+++ b/zip.c
@@ -60,7 +60,6 @@ static int dump_final(void *const buf, const size_t n, bool *const done,
{
if (errno == EAGAIN || errno == EWOULDBLOCK)
{
- free_zip(z);
*done = true;
return 0;
}
@@ -251,12 +250,8 @@ static int step(void *const buf, const size_t n, bool *const done,
void *const user, void *const args)
{
struct zip *const z = args;
- const int ret = z->next(buf, n, done, user, z);
- if (ret < 0)
- free_zip(z);
-
- return ret;
+ return z->next(buf, n, done, user, z);
}
int zip(const char *const dir, struct http_response *const r)
@@ -326,7 +321,8 @@ int zip(const char *const dir, struct http_response *const r)
{
.status = HTTP_STATUS_OK,
.chunk = step,
- .args = z
+ .args = z,
+ .free = free_zip
};
if (http_response_add_header(r, "Content-Type", "application/zip")