Re: Possibly solved invalid free() in git-remote-http from Git 1.7.2.1
- From
Tay Ray Chuan <rctay89@gmail.com>
- Date
- Aug 2, 2011, 02:51 UTC
- Message-ID
- <20110802105124.000021c3@unknown>
- In-Reply-To
- <20110801180018.GA10636@sigill.intra.peff.net>
On Mon, 1 Aug 2011 12:00:19 -0600 Jeff King <peff@peff.net> wrote:
> Hmm. The memory management in the function seems weird to me.
How about this?
-->8--
diff --git a/http.c b/http.c index b2ae8de..4da6293 100644 --- a/http.c +++ b/http.c @@ -1116,9 +1116,8 @@ struct http_pack_request *new_http_pack_request( struct strbuf buf = STRBUF_INIT; struct http_pack_request *preq; - preq = xmalloc(sizeof(*preq)); + preq = xcalloc(1, sizeof(*preq)); preq->target = target; - preq->range_header = NULL; end_url_with_slash(&buf, base_url); strbuf_addf(&buf, "objects/pack/pack-%s.pack", @@ -1210,7 +1209,7 @@ struct http_object_request *new_http_object_request(const char *base_url, struct curl_slist *range_header = NULL; struct http_object_request *freq; - freq = xmalloc(sizeof(*freq)); + freq = xcalloc(1, sizeof(*freq)); hashcpy(freq->sha1, sha1); freq->localfile = -1; @@ -1248,8 +1247,6 @@ struct http_object_request *new_http_object_request(const char *base_url, goto abort; } - memset(&freq->stream, 0, sizeof(freq->stream)); - git_inflate_init(&freq->stream); git_SHA1_Init(&freq->c); @@ -1324,7 +1321,6 @@ struct http_object_request *new_http_object_request(const char *base_url, return freq; abort: - free(filename); free(freq->url); free(freq); return NULL; -- Cheers, Ray Chuan