Fix memory leak on http_server.c (#1412)

This is in response to issue #1365.
The clang static analyzer basically claims that there is a memory leak
happening in `parse_http_request_1` for the variable `kv`. The leak is
triggered when evhttp_parse_query_str fails and is unable to obtain key
value pairs for a given URI. In this case ret is freed, however kv is
still not freed and thereafter not used. Therefore as a patch I am
freeing kv right after ret is freed.

Please let me know if this patch is helpful :)

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
This commit is contained in:
ashamedbit 2024-03-02 17:10:53 -05:00 committed by GitHub
parent 294a2b69a0
commit 68b9f19f7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -172,6 +172,10 @@ static struct http_request *parse_http_request_1(struct http_request *ret, char
if (evhttp_parse_query_str(query, kv) < 0) {
free(ret);
ret = NULL;
if (kv) {
// kv no longer assigned on this path
free(kv);
}
} else {
ret->headers = (struct http_headers *)calloc(sizeof(struct http_headers), 1);
ret->headers->uri_headers = kv;