{"thread":{"id":"11246","subject":"[PATCH 2/2] Fix some memory leaks in various places","startedAt":"2007-12-11T21:19:56Z","lastAt":"2007-12-11T22:50:21Z","messageCount":6,"participants":["Mike Hommey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"62806","messageId":"1197407997-22945-1-git-send-email-mh@glandium.org","threadId":"11246","inReplyTo":null,"subject":"[PATCH 1/2] Fix XML parser leaks in http-push","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-11T21:19:56Z","receivedAt":"2007-12-11T21:19:56Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"XML_Parser were never freed. While at it, move the parser initialization to\nright before it is needed.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n http-push.c |   15 +++++++++------\n 1 files changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex a4a9d1c..f5ba850 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1189,8 +1189,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tchar *ep;\n \tchar timeout_header[25];\n \tstruct remote_lock *lock = NULL;\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \n@@ -1250,6 +1248,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1268,6 +1268,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock->timeout = -1;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start LOCK request\\n\");\n@@ -1428,8 +1429,6 @@ static void remote_ls(const char *path, int flags,\n \tstruct slot_results results;\n \tstruct strbuf in_buffer = STRBUF_INIT;\n \tstruct buffer out_buffer = { 0, STRBUF_INIT };\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tstruct remote_ls_ctx ls;\n@@ -1463,6 +1462,8 @@ static void remote_ls(const char *path, int flags,\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1481,6 +1482,7 @@ static void remote_ls(const char *path, int flags,\n \t\t\t\t\tXML_ErrorString(\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n@@ -1512,8 +1514,6 @@ static int locking_available(void)\n \tstruct slot_results results;\n \tstruct strbuf in_buffer = STRBUF_INIT;\n \tstruct buffer out_buffer = { 0, STRBUF_INIT };\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tint lock_flags = 0;\n@@ -1538,6 +1538,8 @@ static int locking_available(void)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1556,6 +1558,7 @@ static int locking_available(void)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock_flags = 0;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n-- \n1.5.3.7\n"},{"id":"62805","messageId":"1197407997-22945-2-git-send-email-mh@glandium.org","threadId":"11246","inReplyTo":"1197407997-22945-1-git-send-email-mh@glandium.org","subject":"[PATCH 2/2] Fix some memory leaks in various places","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-11T21:19:57Z","receivedAt":"2007-12-11T21:19:57Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n builtin-init-db.c |    1 +\n http-walker.c     |   10 ++++++++++\n walker.c          |    2 ++\n 3 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex e1393b8..df61758 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -415,6 +415,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tsafe_create_dir(path, 1);\n \tstrcpy(path+len, \"/info\");\n \tsafe_create_dir(path, 1);\n+\tfree(path);\n \n \tif (shared_repository) {\n \t\tchar buf[10];\ndiff --git a/http-walker.c b/http-walker.c\nindex 2c37868..1a02f86 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -231,6 +231,8 @@ static void finish_object_request(struct object_request *obj_req)\n {\n \tstruct stat st;\n \n+\tfree(obj_req->url);\n+\n \tfchmod(obj_req->local, 0444);\n \tclose(obj_req->local); obj_req->local = -1;\n \n@@ -897,9 +899,17 @@ static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)\n static void cleanup(struct walker *walker)\n {\n \tstruct walker_data *data = walker->data;\n+\tstruct alt_base *prev_altbase, *altbase = data->alt;\n+\twhile (altbase) {\n+\t\tfree(altbase->base);\n+\t\tprev_altbase = altbase;\n+\t\taltbase = altbase->next;\n+\t\tfree(prev_altbase);\n+\t}\n \thttp_cleanup();\n \n \tcurl_slist_free_all(data->no_pragma_header);\n+\tfree(data);\n }\n \n struct walker *get_http_walker(const char *url)\ndiff --git a/walker.c b/walker.c\nindex 397b80d..7473e90 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -299,6 +299,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,\n \t\t\tgoto unlock_and_fail;\n \t}\n \tfree(msg);\n+\tfree(sha1);\n \n \treturn 0;\n \n@@ -306,6 +307,7 @@ unlock_and_fail:\n \tfor (i = 0; i < targets; i++)\n \t\tif (lock[i])\n \t\t\tunlock_ref(lock[i]);\n+\tfree(sha1);\n \n \treturn -1;\n }\n-- \n1.5.3.7\n"},{"id":"62815","messageId":"1197410395-30045-1-git-send-email-mh@glandium.org","threadId":"11246","inReplyTo":"1197407997-22945-2-git-send-email-mh@glandium.org","subject":"[PATCH 3/2] Fix small memory leaks induced by diff_tree_setup_paths","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-11T21:59:55Z","receivedAt":"2007-12-11T21:59:55Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Run diff_tree_release_paths in the appropriate places, and add a test to\navoid NULL dereference. Better safe than sorry.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\n There are a few more occurrences of diff_tree_setup_paths for which I don't\n know the code enough to correctly place the corresponding\n diff_tree_release_paths. Interesting the function existed but was never\n actually used ;)\n\n builtin-blame.c |    4 +++-\n builtin-reset.c |    1 +\n tree-diff.c     |    4 +++-\n 3 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-blame.c b/builtin-blame.c\nindex 523e55a..041901b 100644\n--- a/builtin-blame.c\n+++ b/builtin-blame.c\n@@ -388,6 +388,7 @@ static struct origin *find_origin(struct scoreboard *sb,\n \t\t}\n \t}\n \tdiff_flush(&diff_opts);\n+\tdiff_tree_release_paths(&diff_opts);\n \tif (porigin) {\n \t\t/*\n \t\t * Create a freestanding copy that is not part of\n@@ -444,6 +445,7 @@ static struct origin *find_rename(struct scoreboard *sb,\n \t\t}\n \t}\n \tdiff_flush(&diff_opts);\n+\tdiff_tree_release_paths(&diff_opts);\n \treturn porigin;\n }\n \n@@ -1167,7 +1169,7 @@ static int find_copy_in_parent(struct scoreboard *sb,\n \t\t}\n \t}\n \tdiff_flush(&diff_opts);\n-\n+\tdiff_tree_release_paths(&diff_opts);\n \treturn retval;\n }\n \ndiff --git a/builtin-reset.c b/builtin-reset.c\nindex 4c61025..713c2d5 100644\n--- a/builtin-reset.c\n+++ b/builtin-reset.c\n@@ -158,6 +158,7 @@ static int read_from_tree(const char *prefix, const char **argv,\n \t\treturn 1;\n \tdiffcore_std(&opt);\n \tdiff_flush(&opt);\n+\tdiff_tree_release_paths(&opt);\n \n \tif (!index_was_discarded)\n \t\t/* The index is still clobbered from do_diff_cache() */\ndiff --git a/tree-diff.c b/tree-diff.c\nindex aa0a100..a2fdf86 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -326,6 +326,7 @@ static void try_to_follow_renames(struct tree_desc *t1, struct tree_desc *t2, co\n \t\tdie(\"unable to set up diff options to follow renames\");\n \tdiff_tree(t1, t2, base, &diff_opts);\n \tdiffcore_std(&diff_opts);\n+\tdiff_tree_release_paths(&diff_opts);\n \n \t/* Go through the new set of filepairing, and see if we find a more interesting one */\n \tfor (i = 0; i < q->nr; i++) {\n@@ -418,7 +419,8 @@ static int count_paths(const char **paths)\n \n void diff_tree_release_paths(struct diff_options *opt)\n {\n-\tfree(opt->pathlens);\n+\tif (opt->pathlens)\n+\t\tfree(opt->pathlens);\n }\n \n void diff_tree_setup_paths(const char **p, struct diff_options *opt)\n-- \n1.5.3.7\n"},{"id":"62821","messageId":"1197412253-927-1-git-send-email-mh@glandium.org","threadId":"11246","inReplyTo":"1197407997-22945-1-git-send-email-mh@glandium.org","subject":"[PATCH 1/2 v2] Fix XML parser leaks in http-push","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-11T22:30:53Z","receivedAt":"2007-12-11T22:30:53Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"XML_Parser were never freed. While at it, move the parser initialization to\nright before it is needed.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\n This one is the same, but against pu, where Junio fixed my strbuf patch in\n a different way than I did.\n\n http-push.c |   15 +++++++++------\n 1 files changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex a76a9e5..c7586b3 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1189,8 +1189,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tchar *ep;\n \tchar timeout_header[25];\n \tstruct remote_lock *lock = NULL;\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \n@@ -1250,6 +1248,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1268,6 +1268,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock->timeout = -1;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start LOCK request\\n\");\n@@ -1428,8 +1429,6 @@ static void remote_ls(const char *path, int flags,\n \tstruct slot_results results;\n \tstruct strbuf in_buffer = STRBUF_INIT;\n \tstruct buffer out_buffer = { STRBUF_INIT, 0 };\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tstruct remote_ls_ctx ls;\n@@ -1463,6 +1462,8 @@ static void remote_ls(const char *path, int flags,\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1481,6 +1482,7 @@ static void remote_ls(const char *path, int flags,\n \t\t\t\t\tXML_ErrorString(\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n@@ -1512,8 +1514,6 @@ static int locking_available(void)\n \tstruct slot_results results;\n \tstruct strbuf in_buffer = STRBUF_INIT;\n \tstruct buffer out_buffer = { STRBUF_INIT, 0 };\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tint lock_flags = 0;\n@@ -1538,6 +1538,8 @@ static int locking_available(void)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1556,6 +1558,7 @@ static int locking_available(void)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock_flags = 0;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n-- \n1.5.3.7.1164.ga23bb-dirty\n"},{"id":"62822","messageId":"7v4peodfkb.fsf@gitster.siamese.dyndns.org","threadId":"11246","inReplyTo":"1197412253-927-1-git-send-email-mh@glandium.org","subject":"Re: [PATCH 1/2 v2] Fix XML parser leaks in http-push","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-11T22:36:36Z","receivedAt":"2007-12-11T22:36:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Hommey <mh@glandium.org> writes:\n\n> XML_Parser were never freed. While at it, move the parser initialization to\n> right before it is needed.\n>\n> Signed-off-by: Mike Hommey <mh@glandium.org>\n> ---\n>\n>  This one is the same, but against pu, where Junio fixed my strbuf patch in\n>  a different way than I did.\n\nTo be very honest, I wish the strbuf patch (that has potentially larger\nimpact) did not take these obviously correct leakfix patches hostage.\n\nWill have to take a look but slowly (I'm at work now).\n"},{"id":"62824","messageId":"1197413421-4759-1-git-send-email-mh@glandium.org","threadId":"11246","inReplyTo":"7v4peodfkb.fsf@gitster.siamese.dyndns.org","subject":"[PATCH 1/2 for master] Fix XML parser leaks in http-push","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-11T22:50:21Z","receivedAt":"2007-12-11T22:50:21Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"XML_Parser were never freed. While at it, move the parser initialization to\nright before it is needed.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\n Same, on top of master.\n\n http-push.c |   15 +++++++++------\n 1 files changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 78283b4..fffbe9c 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1275,8 +1275,6 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tchar *ep;\n \tchar timeout_header[25];\n \tstruct remote_lock *lock = NULL;\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \n@@ -1345,6 +1343,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1363,6 +1363,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock->timeout = -1;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start LOCK request\\n\");\n@@ -1525,8 +1526,6 @@ static void remote_ls(const char *path, int flags,\n \tstruct buffer out_buffer;\n \tchar *in_data;\n \tchar *out_data;\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tstruct remote_ls_ctx ls;\n@@ -1569,6 +1568,8 @@ static void remote_ls(const char *path, int flags,\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1587,6 +1588,7 @@ static void remote_ls(const char *path, int flags,\n \t\t\t\t\tXML_ErrorString(\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n@@ -1620,8 +1622,6 @@ static int locking_available(void)\n \tstruct buffer out_buffer;\n \tchar *in_data;\n \tchar *out_data;\n-\tXML_Parser parser = XML_ParserCreate(NULL);\n-\tenum XML_Status result;\n \tstruct curl_slist *dav_headers = NULL;\n \tstruct xml_ctx ctx;\n \tint lock_flags = 0;\n@@ -1658,6 +1658,8 @@ static int locking_available(void)\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result == CURLE_OK) {\n+\t\t\tXML_Parser parser = XML_ParserCreate(NULL);\n+\t\t\tenum XML_Status result;\n \t\t\tctx.name = xcalloc(10, 1);\n \t\t\tctx.len = 0;\n \t\t\tctx.cdata = NULL;\n@@ -1676,6 +1678,7 @@ static int locking_available(void)\n \t\t\t\t\t\tXML_GetErrorCode(parser)));\n \t\t\t\tlock_flags = 0;\n \t\t\t}\n+\t\t\tXML_ParserFree(parser);\n \t\t}\n \t} else {\n \t\tfprintf(stderr, \"Unable to start PROPFIND request\\n\");\n-- \n1.5.3.7.1164.ga23bb-dirty\n"}]}