From: Junio C Hamano Date: Mon, 14 Sep 2009 21:48:27 +0000 (-0700) Subject: Merge branch 'maint' X-Git-Tag: v1.6.5-rc2~30 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/2b621c1a3aac23b8258885a9b4658d9ac993742f?ds=inline;hp=-c Merge branch 'maint' * maint: http.c: avoid freeing an uninitialized pointer --- 2b621c1a3aac23b8258885a9b4658d9ac993742f diff --combined http.c index 84def9ff24,15926d8d6d..23b2a1932c --- a/http.c +++ b/http.c @@@ -866,7 -866,7 +866,7 @@@ static int fetch_pack_index(unsigned ch int ret = 0; char *hex = xstrdup(sha1_to_hex(sha1)); char *filename; - char *url; + char *url = NULL; struct strbuf buf = STRBUF_INIT; if (has_pack_index(sha1)) { @@@ -995,6 -995,7 +995,6 @@@ int finish_http_pack_request(struct htt struct http_pack_request *new_http_pack_request( struct packed_git *target, const char *base_url) { - char *url; char *filename; long prev_posn = 0; char range[RANGE_HEADER_SIZE]; @@@ -1008,7 -1009,8 +1008,7 @@@ end_url_with_slash(&buf, base_url); strbuf_addf(&buf, "objects/pack/pack-%s.pack", sha1_to_hex(target->sha1)); - url = strbuf_detach(&buf, NULL); - preq->url = xstrdup(url); + preq->url = strbuf_detach(&buf, NULL); filename = sha1_pack_name(target->sha1); snprintf(preq->filename, sizeof(preq->filename), "%s", filename); @@@ -1024,7 -1026,7 +1024,7 @@@ preq->slot->local = preq->packfile; curl_easy_setopt(preq->slot->curl, CURLOPT_FILE, preq->packfile); curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(preq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(preq->slot->curl, CURLOPT_URL, preq->url); curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); @@@ -1048,8 -1050,6 +1048,8 @@@ abort: free(filename); + free(preq->url); + free(preq); return NULL; } @@@ -1089,6 -1089,7 +1089,6 @@@ struct http_object_request *new_http_ob char *hex = sha1_to_hex(sha1); char *filename; char prevfile[PATH_MAX]; - char *url; int prevlocal; unsigned char prev_buf[PREV_BUF_SIZE]; ssize_t prev_read = 0; @@@ -1142,7 -1143,8 +1142,7 @@@ git_SHA1_Init(&freq->c); - url = get_remote_object_url(base_url, hex, 0); - freq->url = xstrdup(url); + freq->url = get_remote_object_url(base_url, hex, 0); /* * If a previous temp file is present, process what was already @@@ -1178,11 -1180,7 +1178,11 @@@ if (prev_posn>0) { prev_posn = 0; lseek(freq->localfile, 0, SEEK_SET); - ftruncate(freq->localfile, 0); + if (ftruncate(freq->localfile, 0) < 0) { + error("Couldn't truncate temporary file %s for %s: %s", + freq->tmpfile, freq->filename, strerror(errno)); + goto abort; + } } } @@@ -1191,7 -1189,7 +1191,7 @@@ curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq); curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr); - curl_easy_setopt(freq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url); curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); /* @@@ -1211,9 -1209,9 +1211,9 @@@ return freq; - free(url); abort: free(filename); + free(freq->url); free(freq); return NULL; }