{"thread":{"id":"11298","subject":"[PATCH 1/2] Fix some more memory leaks in http-push.c","startedAt":"2007-12-14T21:18:00Z","lastAt":"2007-12-14T22:17:53Z","messageCount":3,"participants":["Mike Hommey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"63208","messageId":"1197667081-9909-1-git-send-email-mh@glandium.org","threadId":"11298","inReplyTo":null,"subject":"[PATCH 1/2] Fix some more memory leaks in http-push.c","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-14T21:18:00Z","receivedAt":"2007-12-14T21:18:00Z","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 http-push.c |   13 +++++++++++--\n 1 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex fffbe9c..fc60bfd 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -925,11 +925,14 @@ static int fetch_index(unsigned char *sha1)\n \t\t\t\t     hex);\n \t\t}\n \t} else {\n+\t\tfree(url);\n \t\treturn error(\"Unable to start request\");\n \t}\n \n-\tif (has_pack_index(sha1))\n+\tif (has_pack_index(sha1)) {\n+\t\tfree(url);\n \t\treturn 0;\n+\t}\n \n \tif (push_verbosely)\n \t\tfprintf(stderr, \"Getting index for pack %s\\n\", hex);\n@@ -939,9 +942,11 @@ static int fetch_index(unsigned char *sha1)\n \tfilename = sha1_pack_index_name(sha1);\n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s.temp\", filename);\n \tindexfile = fopen(tmpfile, \"a\");\n-\tif (!indexfile)\n+\tif (!indexfile) {\n+\t\tfree(url);\n \t\treturn error(\"Unable to open local file %s for pack index\",\n \t\t\t     tmpfile);\n+\t}\n \n \tslot = get_active_slot();\n \tslot->results = &results;\n@@ -1135,10 +1140,12 @@ int fetch_ref(char *ref, unsigned char *sha1)\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n+\t\tfree(url);\n \t\tif (results.curl_result != CURLE_OK)\n \t\t\treturn error(\"Couldn't get %s for %s\\n%s\",\n \t\t\t\t     url, ref, curl_errorstr);\n \t} else {\n+\t\tfree(url);\n \t\treturn error(\"Unable to start request\");\n \t}\n \n@@ -2107,6 +2114,7 @@ static int remote_exists(const char *path)\n \n         if (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n+\t\tfree(url);\n \t\tif (results.http_code == 404)\n \t\t\treturn 0;\n \t\telse if (results.curl_result == CURLE_OK)\n@@ -2114,6 +2122,7 @@ static int remote_exists(const char *path)\n \t\telse\n \t\t\tfprintf(stderr, \"HEAD HTTP error %ld\\n\", results.http_code);\n \t} else {\n+\t\tfree(url);\n \t\tfprintf(stderr, \"Unable to start HEAD request\\n\");\n \t}\n \n-- \n1.5.4.rc0.8.gbf4af-dirty\n"},{"id":"63209","messageId":"1197667081-9909-2-git-send-email-mh@glandium.org","threadId":"11298","inReplyTo":"1197667081-9909-1-git-send-email-mh@glandium.org","subject":"[PATCH 2/2] Fix random sha1 in error message in http-fetch and http-push","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-12-14T21:18:01Z","receivedAt":"2007-12-14T21:18:01Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"When a downloaded ref doesn't contain a sha1, the error message displays\na random sha1 because of uninitialized memory. This happens when cloning\na repository that is already a clone of another one, in which case\nrefs/remotes/origin/HEAD is a symref.\n\nSigned-off-by: Mike Hommey <mh@glandium.org>\n---\n\nPlease note that this is already fixed in my strbuf patch for these files,\nwhich had been applied in pu, but it seems to have disappeared from pu's\nhistory. This also means the strbuf patch conflicts with this one. Please\ntell me if you want a new strbuf patch made after this one.\n\n http-push.c   |    5 +++--\n http-walker.c |    5 +++--\n 2 files changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex fc60bfd..7f1d043 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1149,9 +1149,10 @@ int fetch_ref(char *ref, unsigned char *sha1)\n \t\treturn error(\"Unable to start request\");\n \t}\n \n+\tif (buffer.posn != 41)\n+\t\treturn 1;\n         hex[40] = '\\0';\n-        get_sha1_hex(hex, sha1);\n-        return 0;\n+        return get_sha1_hex(hex, sha1);\n }\n \n static void one_remote_object(const char *hex)\ndiff --git a/http-walker.c b/http-walker.c\nindex a3fb596..68b5108 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -986,9 +986,10 @@ static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)\n \t\treturn error(\"Unable to start request\");\n \t}\n \n+\tif (buffer.posn != 41)\n+\t\treturn 1;\n         hex[40] = '\\0';\n-        get_sha1_hex(hex, sha1);\n-        return 0;\n+        return get_sha1_hex(hex, sha1);\n }\n \n static void cleanup(struct walker *walker)\n-- \n1.5.4.rc0.8.gbf4af-dirty\n"},{"id":"63215","messageId":"7vbq8sq5ta.fsf@gitster.siamese.dyndns.org","threadId":"11298","inReplyTo":"1197667081-9909-2-git-send-email-mh@glandium.org","subject":"Re: [PATCH 2/2] Fix random sha1 in error message in http-fetch and http-push","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-14T22:17:53Z","receivedAt":"2007-12-14T22:17:53Z","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> Please note that this is already fixed in my strbuf patch for these files,\n> which had been applied in pu, but it seems to have disappeared from pu's\n> history. This also means the strbuf patch conflicts with this one. Please\n> tell me if you want a new strbuf patch made after this one.\n\nThe branch 'pu' almost always rewind and gets rebuilt from the tip of\n'next'.  Since I am more worried about master and next, even more so\nthan usual these days, most of the backburnered topics are not even in\n'pu' but I still keep tips of them not to lose (they are found in\n'offcuts').\n\nGive me a few days to get back to your series.  I think it is a series\nof good clean-up patches, (I just read [1/2] which was trivially correct\nalthough I am not sure if it is the optimum fix to sprinkle free(url) to\neverywhere we have return), but I just haven't got around to them.\n"}]}