* [PATCH 1/2] Fix XML parser leaks in http-push
@ 2007-12-11 21:19 Mike Hommey
2007-12-11 21:19 ` [PATCH 2/2] Fix some memory leaks in various places Mike Hommey
2007-12-11 22:30 ` [PATCH 1/2 v2] Fix XML parser leaks in http-push Mike Hommey
0 siblings, 2 replies; 6+ messages in thread
From: Mike Hommey @ 2007-12-11 21:19 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
XML_Parser were never freed. While at it, move the parser initialization to
right before it is needed.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
http-push.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/http-push.c b/http-push.c
index a4a9d1c..f5ba850 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1189,8 +1189,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
char *ep;
char timeout_header[25];
struct remote_lock *lock = NULL;
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
@@ -1250,6 +1248,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1268,6 +1268,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
XML_GetErrorCode(parser)));
lock->timeout = -1;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start LOCK request\n");
@@ -1428,8 +1429,6 @@ static void remote_ls(const char *path, int flags,
struct slot_results results;
struct strbuf in_buffer = STRBUF_INIT;
struct buffer out_buffer = { 0, STRBUF_INIT };
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
struct remote_ls_ctx ls;
@@ -1463,6 +1462,8 @@ static void remote_ls(const char *path, int flags,
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1481,6 +1482,7 @@ static void remote_ls(const char *path, int flags,
XML_ErrorString(
XML_GetErrorCode(parser)));
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
@@ -1512,8 +1514,6 @@ static int locking_available(void)
struct slot_results results;
struct strbuf in_buffer = STRBUF_INIT;
struct buffer out_buffer = { 0, STRBUF_INIT };
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
int lock_flags = 0;
@@ -1538,6 +1538,8 @@ static int locking_available(void)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1556,6 +1558,7 @@ static int locking_available(void)
XML_GetErrorCode(parser)));
lock_flags = 0;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
--
1.5.3.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] Fix some memory leaks in various places
2007-12-11 21:19 [PATCH 1/2] Fix XML parser leaks in http-push Mike Hommey
@ 2007-12-11 21:19 ` Mike Hommey
2007-12-11 21:59 ` [PATCH 3/2] Fix small memory leaks induced by diff_tree_setup_paths Mike Hommey
2007-12-11 22:30 ` [PATCH 1/2 v2] Fix XML parser leaks in http-push Mike Hommey
1 sibling, 1 reply; 6+ messages in thread
From: Mike Hommey @ 2007-12-11 21:19 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
Signed-off-by: Mike Hommey <mh@glandium.org>
---
builtin-init-db.c | 1 +
http-walker.c | 10 ++++++++++
walker.c | 2 ++
3 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index e1393b8..df61758 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -415,6 +415,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
safe_create_dir(path, 1);
strcpy(path+len, "/info");
safe_create_dir(path, 1);
+ free(path);
if (shared_repository) {
char buf[10];
diff --git a/http-walker.c b/http-walker.c
index 2c37868..1a02f86 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -231,6 +231,8 @@ static void finish_object_request(struct object_request *obj_req)
{
struct stat st;
+ free(obj_req->url);
+
fchmod(obj_req->local, 0444);
close(obj_req->local); obj_req->local = -1;
@@ -897,9 +899,17 @@ static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
static void cleanup(struct walker *walker)
{
struct walker_data *data = walker->data;
+ struct alt_base *prev_altbase, *altbase = data->alt;
+ while (altbase) {
+ free(altbase->base);
+ prev_altbase = altbase;
+ altbase = altbase->next;
+ free(prev_altbase);
+ }
http_cleanup();
curl_slist_free_all(data->no_pragma_header);
+ free(data);
}
struct walker *get_http_walker(const char *url)
diff --git a/walker.c b/walker.c
index 397b80d..7473e90 100644
--- a/walker.c
+++ b/walker.c
@@ -299,6 +299,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
goto unlock_and_fail;
}
free(msg);
+ free(sha1);
return 0;
@@ -306,6 +307,7 @@ unlock_and_fail:
for (i = 0; i < targets; i++)
if (lock[i])
unlock_ref(lock[i]);
+ free(sha1);
return -1;
}
--
1.5.3.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/2] Fix small memory leaks induced by diff_tree_setup_paths
2007-12-11 21:19 ` [PATCH 2/2] Fix some memory leaks in various places Mike Hommey
@ 2007-12-11 21:59 ` Mike Hommey
0 siblings, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2007-12-11 21:59 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
Run diff_tree_release_paths in the appropriate places, and add a test to
avoid NULL dereference. Better safe than sorry.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
There are a few more occurrences of diff_tree_setup_paths for which I don't
know the code enough to correctly place the corresponding
diff_tree_release_paths. Interesting the function existed but was never
actually used ;)
builtin-blame.c | 4 +++-
builtin-reset.c | 1 +
tree-diff.c | 4 +++-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index 523e55a..041901b 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -388,6 +388,7 @@ static struct origin *find_origin(struct scoreboard *sb,
}
}
diff_flush(&diff_opts);
+ diff_tree_release_paths(&diff_opts);
if (porigin) {
/*
* Create a freestanding copy that is not part of
@@ -444,6 +445,7 @@ static struct origin *find_rename(struct scoreboard *sb,
}
}
diff_flush(&diff_opts);
+ diff_tree_release_paths(&diff_opts);
return porigin;
}
@@ -1167,7 +1169,7 @@ static int find_copy_in_parent(struct scoreboard *sb,
}
}
diff_flush(&diff_opts);
-
+ diff_tree_release_paths(&diff_opts);
return retval;
}
diff --git a/builtin-reset.c b/builtin-reset.c
index 4c61025..713c2d5 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -158,6 +158,7 @@ static int read_from_tree(const char *prefix, const char **argv,
return 1;
diffcore_std(&opt);
diff_flush(&opt);
+ diff_tree_release_paths(&opt);
if (!index_was_discarded)
/* The index is still clobbered from do_diff_cache() */
diff --git a/tree-diff.c b/tree-diff.c
index aa0a100..a2fdf86 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -326,6 +326,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co
die("unable to set up diff options to follow renames");
diff_tree(t1, t2, base, &diff_opts);
diffcore_std(&diff_opts);
+ diff_tree_release_paths(&diff_opts);
/* Go through the new set of filepairing, and see if we find a more interesting one */
for (i = 0; i < q->nr; i++) {
@@ -418,7 +419,8 @@ static int count_paths(const char **paths)
void diff_tree_release_paths(struct diff_options *opt)
{
- free(opt->pathlens);
+ if (opt->pathlens)
+ free(opt->pathlens);
}
void diff_tree_setup_paths(const char **p, struct diff_options *opt)
--
1.5.3.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/2 v2] Fix XML parser leaks in http-push
2007-12-11 21:19 [PATCH 1/2] Fix XML parser leaks in http-push Mike Hommey
2007-12-11 21:19 ` [PATCH 2/2] Fix some memory leaks in various places Mike Hommey
@ 2007-12-11 22:30 ` Mike Hommey
2007-12-11 22:36 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Mike Hommey @ 2007-12-11 22:30 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
XML_Parser were never freed. While at it, move the parser initialization to
right before it is needed.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
This one is the same, but against pu, where Junio fixed my strbuf patch in
a different way than I did.
http-push.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/http-push.c b/http-push.c
index a76a9e5..c7586b3 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1189,8 +1189,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
char *ep;
char timeout_header[25];
struct remote_lock *lock = NULL;
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
@@ -1250,6 +1248,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1268,6 +1268,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
XML_GetErrorCode(parser)));
lock->timeout = -1;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start LOCK request\n");
@@ -1428,8 +1429,6 @@ static void remote_ls(const char *path, int flags,
struct slot_results results;
struct strbuf in_buffer = STRBUF_INIT;
struct buffer out_buffer = { STRBUF_INIT, 0 };
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
struct remote_ls_ctx ls;
@@ -1463,6 +1462,8 @@ static void remote_ls(const char *path, int flags,
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1481,6 +1482,7 @@ static void remote_ls(const char *path, int flags,
XML_ErrorString(
XML_GetErrorCode(parser)));
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
@@ -1512,8 +1514,6 @@ static int locking_available(void)
struct slot_results results;
struct strbuf in_buffer = STRBUF_INIT;
struct buffer out_buffer = { STRBUF_INIT, 0 };
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
int lock_flags = 0;
@@ -1538,6 +1538,8 @@ static int locking_available(void)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1556,6 +1558,7 @@ static int locking_available(void)
XML_GetErrorCode(parser)));
lock_flags = 0;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
--
1.5.3.7.1164.ga23bb-dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2 v2] Fix XML parser leaks in http-push
2007-12-11 22:30 ` [PATCH 1/2 v2] Fix XML parser leaks in http-push Mike Hommey
@ 2007-12-11 22:36 ` Junio C Hamano
2007-12-11 22:50 ` [PATCH 1/2 for master] " Mike Hommey
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-12-11 22:36 UTC (permalink / raw)
To: Mike Hommey; +Cc: git
Mike Hommey <mh@glandium.org> writes:
> XML_Parser were never freed. While at it, move the parser initialization to
> right before it is needed.
>
> Signed-off-by: Mike Hommey <mh@glandium.org>
> ---
>
> This one is the same, but against pu, where Junio fixed my strbuf patch in
> a different way than I did.
To be very honest, I wish the strbuf patch (that has potentially larger
impact) did not take these obviously correct leakfix patches hostage.
Will have to take a look but slowly (I'm at work now).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2 for master] Fix XML parser leaks in http-push
2007-12-11 22:36 ` Junio C Hamano
@ 2007-12-11 22:50 ` Mike Hommey
0 siblings, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2007-12-11 22:50 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
XML_Parser were never freed. While at it, move the parser initialization to
right before it is needed.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
Same, on top of master.
http-push.c | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/http-push.c b/http-push.c
index 78283b4..fffbe9c 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1275,8 +1275,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
char *ep;
char timeout_header[25];
struct remote_lock *lock = NULL;
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
@@ -1345,6 +1343,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1363,6 +1363,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
XML_GetErrorCode(parser)));
lock->timeout = -1;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start LOCK request\n");
@@ -1525,8 +1526,6 @@ static void remote_ls(const char *path, int flags,
struct buffer out_buffer;
char *in_data;
char *out_data;
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
struct remote_ls_ctx ls;
@@ -1569,6 +1568,8 @@ static void remote_ls(const char *path, int flags,
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1587,6 +1588,7 @@ static void remote_ls(const char *path, int flags,
XML_ErrorString(
XML_GetErrorCode(parser)));
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
@@ -1620,8 +1622,6 @@ static int locking_available(void)
struct buffer out_buffer;
char *in_data;
char *out_data;
- XML_Parser parser = XML_ParserCreate(NULL);
- enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
int lock_flags = 0;
@@ -1658,6 +1658,8 @@ static int locking_available(void)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result == CURLE_OK) {
+ XML_Parser parser = XML_ParserCreate(NULL);
+ enum XML_Status result;
ctx.name = xcalloc(10, 1);
ctx.len = 0;
ctx.cdata = NULL;
@@ -1676,6 +1678,7 @@ static int locking_available(void)
XML_GetErrorCode(parser)));
lock_flags = 0;
}
+ XML_ParserFree(parser);
}
} else {
fprintf(stderr, "Unable to start PROPFIND request\n");
--
1.5.3.7.1164.ga23bb-dirty
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-12-11 22:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-11 21:19 [PATCH 1/2] Fix XML parser leaks in http-push Mike Hommey
2007-12-11 21:19 ` [PATCH 2/2] Fix some memory leaks in various places Mike Hommey
2007-12-11 21:59 ` [PATCH 3/2] Fix small memory leaks induced by diff_tree_setup_paths Mike Hommey
2007-12-11 22:30 ` [PATCH 1/2 v2] Fix XML parser leaks in http-push Mike Hommey
2007-12-11 22:36 ` Junio C Hamano
2007-12-11 22:50 ` [PATCH 1/2 for master] " Mike Hommey
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).