summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2024-09-25 00:02:13 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-25 19:24:55 +0200
commit8bdb84ebbbfadf71ae1760e68be5422cbe4872c6 (patch)
tree17811a74f2bcfeb1fa5a1e6cf8f71a0afd427e67
parenthttp: fix leak of http_object_request struct (diff)
downloadgit-8bdb84ebbbfadf71ae1760e68be5422cbe4872c6.tar.xz
git-8bdb84ebbbfadf71ae1760e68be5422cbe4872c6.zip
http: call git_inflate_end() when releasing http_object_request
In new_http_object_request(), we initialize the zlib stream with git_inflate_init(). We must have a matching git_inflate_end() to avoid leaking any memory allocated by zlib. In most cases this happens in finish_http_object_request(), but we don't always get there. If we abort a request mid-stream, then we may clean it up without hitting that function. We can't just add a git_inflate_end() call to the release function, though. That would double-free the cases that did actually finish. Instead, we'll move the call from the finish function to the release function. This does delay it for the cases that do finish, but I don't think it matters. We should have already reached Z_STREAM_END (and complain if we didn't), and we do not record any status code from git_inflate_end(). This leak is triggered by t5550 at least (and probably other dumb-http tests). I did find one other related spot of interest. If we try to read a previously downloaded file and fail, we reset the stream by calling memset() followed by a fresh git_inflate_init(). I don't think this case is triggered in the test suite, but it seemed like an obvious leak, so I added the appropriate git_inflate_end() before the memset() there. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--http.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/http.c b/http.c
index d0242ffb50..4d841becca 100644
--- a/http.c
+++ b/http.c
@@ -2726,6 +2726,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
* file; also rewind to the beginning of the local file.
*/
if (prev_read == -1) {
+ git_inflate_end(&freq->stream);
memset(&freq->stream, 0, sizeof(freq->stream));
git_inflate_init(&freq->stream);
the_hash_algo->init_fn(&freq->c);
@@ -2799,7 +2800,6 @@ int finish_http_object_request(struct http_object_request *freq)
return -1;
}
- git_inflate_end(&freq->stream);
the_hash_algo->final_oid_fn(&freq->real_oid, &freq->c);
if (freq->zret != Z_STREAM_END) {
unlink_or_warn(freq->tmpfile.buf);
@@ -2840,6 +2840,7 @@ void release_http_object_request(struct http_object_request **freq_p)
}
curl_slist_free_all(freq->headers);
strbuf_release(&freq->tmpfile);
+ git_inflate_end(&freq->stream);
free(freq);
*freq_p = NULL;