From 66ef564b13bde66cba4d2e37b35ccba4099e4d91 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Tue, 11 May 2021 22:41:37 -0700 Subject: [PATCH] Fix memory leak in `?type=...` feature Passing `?type=foo/bar` in the query string makes Webdis return the response with a `Content-Type: foo/bar` header (this is useful to serve files from Webdis, e.g. web page or their dependencies such as CSS, images, etc). I discovered with Valgrind that the *value* of this query string parameter was leaked and never freed, which would likely not cause a huge issue but would still gradually grow the memory usage. There were 2 different functions taking care of this parameter, the first calling strdup(3) on it and the second *transferring* pointer ownership into it (meaning overwriting the just-strdup'd value). This is now fixed, Webdis no longer leaks this small string, and an allocation was avoided. --- src/cmd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index e87cdd9..290df87 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -356,8 +356,7 @@ cmd_select_format(struct http_client *client, struct cmd *cmd, /* the user can force it with ?type=some/thing */ if(client->type) { *f_format = custom_type_reply; - cmd->mime = strdup(client->type); - cmd->mime_free = 1; + /* /!\ we don't copy cmd->mime, this is done soon after in cmd_setup */ } if(found) {