{"thread":{"id":"479","subject":"[PATCH] Fix memory leaks in read_tree_recursive()","startedAt":"2005-05-04T23:19:59Z","lastAt":"2005-05-05T00:08:15Z","messageCount":4,"participants":["Jonas Fonseca","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2597","messageId":"20050504231959.GA25475@diku.dk","threadId":"479","inReplyTo":null,"subject":"[PATCH] Fix memory leaks in read_tree_recursive()","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-05-04T23:19:59Z","receivedAt":"2005-05-04T23:19:59Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"This patch fixes memory leaks in the error path of\nread_tree_recursive().\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n\n--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c  (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6)\n+++ uncommitted/tree.c  (mode:100644)\n@@ -39,14 +39,18 @@\n \t\tif (S_ISDIR(mode)) {\n \t\t\tint retval;\n \t\t\tint pathlen = strlen(path);\n-\t\t\tchar *newbase = xmalloc(baselen + 1 + pathlen);\n+\t\t\tchar *newbase;\n \t\t\tvoid *eltbuf;\n \t\t\tchar elttype[20];\n \t\t\tunsigned long eltsize;\n \n \t\t\teltbuf = read_sha1_file(sha1, elttype, &eltsize);\n-\t\t\tif (!eltbuf || strcmp(elttype, \"tree\"))\n+\t\t\tif (!eltbuf || strcmp(elttype, \"tree\")) {\n+\t\t\t\tif (eltbuf) mem_free(eltbuf);\n \t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\tnewbase = xmalloc(baselen + 1 + pathlen);\n \t\t\tmemcpy(newbase, base, baselen);\n \t\t\tmemcpy(newbase + baselen, path, pathlen);\n \t\t\tnewbase[baselen + pathlen] = '/';\n\n-- \nJonas Fonseca\n"},{"id":"2598","messageId":"20050504233936.GA25873@diku.dk","threadId":"479","inReplyTo":"20050504231959.GA25475@diku.dk","subject":"[PATCH] Fix memory leaks in read_tree_recursive()","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-05-04T23:39:36Z","receivedAt":"2005-05-04T23:39:36Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"This patch fixes memory leaks in read_tree_recursive().\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n\n---\n\nSorry, typo in the previous patch. I will try to be more careful.\nThis patch has already been applied to cogito.\n\n--- 571c0f4599fbeefd995bbc24480add1575c36c94/tree.c  (mode:100644 sha1:4a26603f6e32866c0db8a01ac1c228be801f76c6)\n+++ uncommitted/tree.c  (mode:100644)\n@@ -39,14 +39,18 @@\n \t\tif (S_ISDIR(mode)) {\n \t\t\tint retval;\n \t\t\tint pathlen = strlen(path);\n-\t\t\tchar *newbase = xmalloc(baselen + 1 + pathlen);\n+\t\t\tchar *newbase;\n \t\t\tvoid *eltbuf;\n \t\t\tchar elttype[20];\n \t\t\tunsigned long eltsize;\n \n \t\t\teltbuf = read_sha1_file(sha1, elttype, &eltsize);\n-\t\t\tif (!eltbuf || strcmp(elttype, \"tree\"))\n+\t\t\tif (!eltbuf || strcmp(elttype, \"tree\")) {\n+\t\t\t\tif (eltbuf) free(eltbuf);\n \t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\tnewbase = xmalloc(baselen + 1 + pathlen);\n \t\t\tmemcpy(newbase, base, baselen);\n \t\t\tmemcpy(newbase + baselen, path, pathlen);\n \t\t\tnewbase[baselen + pathlen] = '/';\n\n-- \nJonas Fonseca\n"},{"id":"2599","messageId":"7vpsw6muay.fsf@assigned-by-dhcp.cox.net","threadId":"479","inReplyTo":"20050504231959.GA25475@diku.dk","subject":"Re: [PATCH] Fix memory leaks in read_tree_recursive()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-04T23:43:17Z","receivedAt":"2005-05-04T23:43:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":">>>>> \"JF\" == Jonas Fonseca <fonseca@diku.dk> writes:\n\nJF> This patch fixes memory leaks in the error path of\nJF> read_tree_recursive().\n\nThe leak seems to be real but what is \"mem_free\"?  Has it been\ncompile tested?\n\nJF> @@ -39,14 +39,18 @@\nJF>  \t\tif (S_ISDIR(mode)) {\nJF>  \t\t\tint retval;\n \nJF> ...\nJF> -\t\t\tif (!eltbuf || strcmp(elttype, \"tree\"))\nJF> +\t\t\tif (!eltbuf || strcmp(elttype, \"tree\")) {\nJF> +\t\t\t\tif (eltbuf) mem_free(eltbuf);\nJF>  \t\t\t\treturn -1;\n\nBtw, who is putting this header in your mail?  It does not make\nsense to me unless Jonas is pseudonym for Linus...\n\n  Mail-Followup-To: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org \n\n\n"},{"id":"2603","messageId":"20050505000815.GA25992@diku.dk","threadId":"479","inReplyTo":"7vpsw6muay.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Fix memory leaks in read_tree_recursive()","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-05-05T00:08:15Z","receivedAt":"2005-05-05T00:08:15Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Junio C Hamano <junkio@cox.net> wrote Wed, May 04, 2005:\n> >>>>> \"JF\" == Jonas Fonseca <fonseca@diku.dk> writes:\n> \n> JF> This patch fixes memory leaks in the error path of\n> JF> read_tree_recursive().\n> \n> The leak seems to be real but what is \"mem_free\"?\n\nThat mem_free() was a bad habbit from the project I usually work on.\n\n> Has it been compile tested?\n\nNo, but the second patch has.\n\nBTW, when compiling git on a FreeBSD box I get these warnings:\n\ndate.c: In function `parse_date':\ndate.c:414: warning: long unsigned int format, time_t arg (arg 4)\ndate.c:414: warning: long unsigned int format, time_t arg (arg 4)\ndate.c: In function `datestamp':\ndate.c:427: warning: long unsigned int format, time_t arg (arg 4)\ndate.c:427: warning: long unsigned int format, time_t arg (arg 4)\ntar-tree.c: In function `write_header':\ntar-tree.c:249: warning: long unsigned int format, time_t arg (arg 3)\nlocal-pull.c: In function `fetch':\nlocal-pull.c:73: warning: long int format, different type arg (arg 4)\n\nbecause time_t is defined as int32_t.  Don't know if they are worth\nfixing at this point.\n\n> JF> @@ -39,14 +39,18 @@\n> JF>  \t\tif (S_ISDIR(mode)) {\n> JF>  \t\t\tint retval;\n>  \n> JF> ...\n> JF> -\t\t\tif (!eltbuf || strcmp(elttype, \"tree\"))\n> JF> +\t\t\tif (!eltbuf || strcmp(elttype, \"tree\")) {\n> JF> +\t\t\t\tif (eltbuf) mem_free(eltbuf);\n> JF>  \t\t\t\treturn -1;\n> \n> Btw, who is putting this header in your mail?  It does not make\n> sense to me unless Jonas is pseudonym for Linus...\n> \n>   Mail-Followup-To: Linus Torvalds <torvalds@osdl.org>, git@vger.kernel.org \n\nMaybe because Mutt knows I am subscribe to this mailing list and assumes\nI don't want to have mail addressed directly to my email address?\n\nI just hit 'g'.\n\n-- \nJonas Fonseca\n"}]}