From: Mike Hommey <mh@glandium.org>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 5/5] Fix various memory leaks in http-push.c and http-walker.c
Date: Mon, 10 Dec 2007 22:36:11 +0100 [thread overview]
Message-ID: <1197322571-25023-5-git-send-email-mh@glandium.org> (raw)
In-Reply-To: <1197322571-25023-4-git-send-email-mh@glandium.org>
Signed-off-by: Mike Hommey <mh@glandium.org>
---
This one, too, sits on top of my strbuf patch for the http code. Note that
I only went for the obvious ones I saw in the code I touched. There is more
in these files.
http-push.c | 32 +++++++++++++++++++++-----------
http-walker.c | 40 +++++++++++++++++++++++++---------------
2 files changed, 46 insertions(+), 26 deletions(-)
diff --git a/http-push.c b/http-push.c
index ad8167e..610ed9c 100644
--- a/http-push.c
+++ b/http-push.c
@@ -924,6 +924,7 @@ static int fetch_index(unsigned char *sha1)
hex);
}
} else {
+ free(url);
return error("Unable to start request");
}
@@ -1114,6 +1115,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
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();
@@ -1124,17 +1126,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);
- 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 {
- 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)
@@ -2033,6 +2041,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;
+ int ret = -1;
sprintf(url, "%s%s", remote->url, path);
@@ -2044,16 +2053,17 @@ static int remote_exists(const char *path)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.http_code == 404)
- return 0;
+ ret = 0;
else if (results.curl_result == CURLE_OK)
- return 1;
+ ret = 1;
else
fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
} else {
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)
diff --git a/http-walker.c b/http-walker.c
index 8dbf9cc..4e878b3 100644
--- 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;
+ int ret = 0;
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) {
- strbuf_release(&buffer);
if (missing_target(&results)) {
repo->got_indices = 1;
- return 0;
+ goto cleanup;
} else {
repo->got_indices = 0;
- return error("%s", curl_errorstr);
+ ret = error("%s", curl_errorstr);
+ goto cleanup;
}
}
} 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;
@@ -701,9 +702,11 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
i++;
}
- strbuf_release(&buffer);
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)
@@ -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;
+ int ret;
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);
- 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 {
- 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 cleanup(struct walker *walker)
--
1.5.3.7.1159.gdd4a4
next prev parent reply other threads:[~2007-12-10 21:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-10 21:36 [PATCH 1/5] Remove the default_headers variable from http-push.c Mike Hommey
2007-12-10 21:36 ` [PATCH 2/5] Remove a CURLOPT_HTTPHEADER (un)setting Mike Hommey
2007-12-10 21:36 ` [PATCH 3/5] Avoid redundant declaration of missing_target() Mike Hommey
2007-12-10 21:36 ` [PATCH 4/5] Correctly initialize buffer in start_put() in http-push.c Mike Hommey
2007-12-10 21:36 ` Mike Hommey [this message]
2007-12-10 23:08 ` [PATCH 6/5] Move fetch_ref from http-push.c and http-walker.c to http.c Mike Hommey
2007-12-11 5:09 ` Junio C Hamano
2007-12-11 6:21 ` Mike Hommey
2007-12-11 7:22 ` Andreas Ericsson
2007-12-11 7:49 ` Mike Hommey
2007-12-11 20:00 ` [New PATCH] " Mike Hommey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1197322571-25023-5-git-send-email-mh@glandium.org \
--to=mh@glandium.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).