http.c: fix an invalid free()
Remove a free() on the static buffer returned by sha1_file_name(). While we're at it, replace xmalloc() calls on the structs http_(object|pack)_request with xcalloc() so that pointers in the structs get initialized to NULL. That way, free()'s are safe - for example, a free() on the url string member when aborting. This fixes an invalid free(). Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Jeff King peff@peff.net Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
Aug 3, 2011 at 19:54 UTC
ec99c9a89a65749093e16aed37d393f646597b31
1 file changed
+2
-6
http.c
+2
-6
@@ -1116,9 +1116,8 @@ struct http_pack_request *new_http_pack_request(
1116
struct strbuf buf = STRBUF_INIT;
1117
struct http_pack_request *preq;
1118
1119
- preq = xmalloc(sizeof(*preq));
1119
+ preq = xcalloc(1, sizeof(*preq));
1120
preq->target = target;
1121
- preq->range_header = NULL;
1121
1122
end_url_with_slash(&buf, base_url);
1123
strbuf_addf(&buf, "objects/pack/pack-%s.pack",
@@ -1210,7 +1209,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
1209
struct curl_slist *range_header = NULL;
1210
struct http_object_request *freq;
1211
1213
- freq = xmalloc(sizeof(*freq));
1212
+ freq = xcalloc(1, sizeof(*freq));
1213
hashcpy(freq->sha1, sha1);
1214
freq->localfile = -1;
1215
@@ -1248,8 +1247,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
1247
goto abort;
1248
}
1249
1251
- memset(&freq->stream, 0, sizeof(freq->stream));
1252
-
1250
git_inflate_init(&freq->stream);
1251
1252
git_SHA1_Init(&freq->c);
@@ -1324,7 +1321,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
1321
return freq;
1322
1323
abort:
1327
- free(filename);
1324
free(freq->url);
1325
free(freq);
1326
return NULL;