Re: Possibly solved invalid free() in git-remote-http from Git 1.7.2.1
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Aug 1, 2011, 15:39 UTC
- Message-ID
- <CACBZZX5s8+O8X2mpexudGEsaQRm+tr0CQvqTZjZ700DN297__w@mail.gmail.com>
- In-Reply-To
- <CACBZZX7s+NeH2jLC9Ym65_rMQkgVmfbCAkqZbBFhTiY9U8uP2A@mail.gmail.com>
On Mon, Aug 1, 2011 at 17:22, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> In case anyone would like to look into this I had this undiagnosed > free() error from git-remote-http in git version 1.7.2.1:
Actually this is still an issue in master, CC-ing Tay who introduced this error.
This evil hack would get around it most of the time, but would introduce another race condition:
diff --git a/http.c b/http.c
index a1ea3db..ba81158 100644
--- a/http.c
+++ b/http.c
@@ -1212,6 +1212,7 @@ struct http_object_request
*new_http_object_request(const char *base_url,
ssize_t prev_read = 0;
long prev_posn = 0;
char range[RANGE_HEADER_SIZE];
+ int allocated_url = 0;
struct curl_slist *range_header = NULL;
struct http_object_request *freq; @@ -1260,6 +1261,7 @@ struct http_object_request
*new_http_object_request(const char *base_url,
git_SHA1_Init(&freq->c); freq->url = get_remote_object_url(base_url, hex, 0);
+ allocated_url = 1; /*
* If a previous temp file is present, process what was already
@@ -1330,7 +1332,8 @@ struct http_object_request
*new_http_object_request(const char *base_url, abort:
free(filename);
- free(freq->url);
+ if (allocated_url)
+ free(freq->url);
free(freq);
return NULL;
}One option would be to memzero freq, but that'll trip up xmalloc which tries to set things to 0xA5 under XMALLOC_POISON. I don't know what the proper way to solve this would be.