Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
Fix various memory leaks in http-push.c and http-walker.c
author
Mike Hommey
<mh@glandium.org>
Mon, 10 Dec 2007 21:36:11 +0000
(22:36 +0100)
committer
Junio C Hamano
<gitster@pobox.com>
Sat, 15 Dec 2007 05:31:59 +0000
(21:31 -0800)
Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http-push.c
patch
|
blob
|
history
http-walker.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
028c297
)
diff --git
a/http-push.c
b/http-push.c
index 0257291b9ba9258558632b1e428df6479a28b9db..af00ea10b96ffe6c2a29d69603d48093dd12e441 100644
(file)
--- a/
http-push.c
+++ b/
http-push.c
@@
-1119,6
+1119,7
@@
int fetch_ref(char *ref, unsigned char *sha1)
char *base = remote->url;
struct active_request_slot *slot;
struct slot_results results;
char *base = remote->url;
struct active_request_slot *slot;
struct slot_results results;
+ int ret;
url = quote_ref_url(base, ref);
slot = get_active_slot();
url = quote_ref_url(base, ref);
slot = get_active_slot();
@@
-1129,19
+1130,23
@@
int fetch_ref(char *ref, unsigned char *sha1)
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
- free(url);
- if (results.curl_result != CURLE_OK)
- return error("Couldn't get %s for %s\n%s",
- url, ref, curl_errorstr);
+ if (results.curl_result == CURLE_OK) {
+ strbuf_rtrim(&buffer);
+ if (buffer.len == 40)
+ ret = get_sha1_hex(buffer.buf, sha1);
+ else
+ ret = 1;
+ } else {
+ ret = error("Couldn't get %s for %s\n%s",
+ url, ref, curl_errorstr);
+ }
} else {
} else {
- free(url);
- return error("Unable to start request");
+ ret = error("Unable to start request");
}
}
- strbuf_rtrim(&buffer);
- if (buffer.len != 40)
- return 1;
- return get_sha1_hex(buffer.buf, sha1);
+ strbuf_release(&buffer);
+ free(url);
+ return ret;
}
static void one_remote_object(const char *hex)
}
static void one_remote_object(const char *hex)
@@
-2043,6
+2048,7
@@
static int remote_exists(const char *path)
char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
struct active_request_slot *slot;
struct slot_results results;
char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
struct active_request_slot *slot;
struct slot_results results;
+ int ret = -1;
sprintf(url, "%s%s", remote->url, path);
sprintf(url, "%s%s", remote->url, path);
@@
-2055,9
+2061,9
@@
static int remote_exists(const char *path)
run_active_slot(slot);
free(url);
if (results.http_code == 404)
run_active_slot(slot);
free(url);
if (results.http_code == 404)
- ret
urn
0;
+ ret
=
0;
else if (results.curl_result == CURLE_OK)
else if (results.curl_result == CURLE_OK)
- ret
urn
1;
+ ret
=
1;
else
fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
} else {
else
fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
} else {
@@
-2065,7
+2071,8
@@
static int remote_exists(const char *path)
fprintf(stderr, "Unable to start HEAD request\n");
}
fprintf(stderr, "Unable to start HEAD request\n");
}
- return -1;
+ free(url);
+ return ret;
}
static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
}
static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
diff --git
a/http-walker.c
b/http-walker.c
index 8dbf9cc369c59d36930c6cf67fda8ed279d50922..4e878b3c8f667e735e4f11abe44910fb9682e49c 100644
(file)
--- a/
http-walker.c
+++ b/
http-walker.c
@@
-644,6
+644,7
@@
static int fetch_indices(struct walker *walker, struct alt_base *repo)
struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
+ int ret = 0;
struct active_request_slot *slot;
struct slot_results results;
struct active_request_slot *slot;
struct slot_results results;
@@
-666,19
+667,19
@@
static int fetch_indices(struct walker *walker, struct alt_base *repo)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
- strbuf_release(&buffer);
if (missing_target(&results)) {
repo->got_indices = 1;
if (missing_target(&results)) {
repo->got_indices = 1;
-
return 0
;
+
goto cleanup
;
} else {
repo->got_indices = 0;
} else {
repo->got_indices = 0;
- return error("%s", curl_errorstr);
+ ret = error("%s", curl_errorstr);
+ goto cleanup;
}
}
} else {
repo->got_indices = 0;
}
}
} else {
repo->got_indices = 0;
-
strbuf_release(&buffer
);
-
return error("Unable to start request")
;
+
ret = error("Unable to start request"
);
+
goto cleanup
;
}
data = buffer.buf;
}
data = buffer.buf;
@@
-701,9
+702,11
@@
static int fetch_indices(struct walker *walker, struct alt_base *repo)
i++;
}
i++;
}
- strbuf_release(&buffer);
repo->got_indices = 1;
repo->got_indices = 1;
- return 0;
+cleanup:
+ strbuf_release(&buffer);
+ free(url);
+ return ret;
}
static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1)
}
static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1)
@@
-939,6
+942,7
@@
static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
const char *base = data->alt->base;
struct active_request_slot *slot;
struct slot_results results;
const char *base = data->alt->base;
struct active_request_slot *slot;
struct slot_results results;
+ int ret;
url = quote_ref_url(base, ref);
slot = get_active_slot();
url = quote_ref_url(base, ref);
slot = get_active_slot();
@@
-949,17
+953,23
@@
static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
- if (results.curl_result != CURLE_OK)
- return error("Couldn't get %s for %s\n%s",
- url, ref, curl_errorstr);
+ if (results.curl_result == CURLE_OK) {
+ strbuf_rtrim(&buffer);
+ if (buffer.len == 40)
+ ret = get_sha1_hex(buffer.buf, sha1);
+ else
+ ret = 1;
+ } else {
+ ret = error("Couldn't get %s for %s\n%s",
+ url, ref, curl_errorstr);
+ }
} else {
} else {
- ret
urn
error("Unable to start request");
+ ret
=
error("Unable to start request");
}
}
- strbuf_rtrim(&buffer);
- if (buffer.len != 40)
- return 1;
- return get_sha1_hex(buffer.buf, sha1);
+ strbuf_release(&buffer);
+ free(url);
+ return ret;
}
static void cleanup(struct walker *walker)
}
static void cleanup(struct walker *walker)