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.
master
Nicolas Favre-Felix 3 years ago
parent 6556039e05
commit 66ef564b13
No known key found for this signature in database
GPG Key ID: C04E7AA8B6F73372

@ -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) {

Loading…
Cancel
Save