{"thread":{"id":"19354","subject":"[PATCH] Fix minor memory leak in init-db","startedAt":"2009-05-14T22:22:24Z","lastAt":"2009-05-17T16:09:17Z","messageCount":5,"participants":["Ammon Riley","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"113968","messageId":"cd3664ac0905141522s3ad78411o9f015d2e7720c8b5@mail.gmail.com","threadId":"19354","inReplyTo":null,"subject":"[PATCH] Fix minor memory leak in init-db","fromName":"Ammon Riley","fromEmail":"ammon.riley@gmail.com","sentAt":"2009-05-14T22:22:24Z","receivedAt":"2009-05-14T22:22:24Z","isPatch":true,"sender":{"key":"ammon.riley@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1801261?v=4"},"body":"There was an xmalloc() for path, but I didn't see a corresponding free().\nDoes it happen somewhere else that I'm not expecting?\n\nSigned-off-by: Ammon Riley <ammon.riley@gmail.com>\n---\n builtin-init-db.c |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex d1fa12a..6969987 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -308,6 +308,8 @@ int init_db(const char *template_dir, unsigned int flags)\n \tstrcpy(path+len, \"/info\");\n \tsafe_create_dir(path, 1);\n\n+\tfree(path);\n+\n \tif (shared_repository) {\n \t\tchar buf[10];\n \t\t/* We do not spell \"group\" and such, so that\n-- \n1.6.3.1.9.g95405b.dirty\n"},{"id":"114117","messageId":"7vzldclt33.fsf@alter.siamese.dyndns.org","threadId":"19354","inReplyTo":"cd3664ac0905141522s3ad78411o9f015d2e7720c8b5@mail.gmail.com","subject":"Re: [PATCH] Fix minor memory leak in init-db","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-16T19:56:48Z","receivedAt":"2009-05-16T19:56:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ammon Riley <ammon.riley@gmail.com> writes:\n\n> There was an xmalloc() for path, but I didn't see a corresponding free().\n> Does it happen somewhere else that I'm not expecting?\n\nIt implicitly happens in exit() in git.c:handle_internal_command()\nafter cmd_init_db() returns the control to it.\n"},{"id":"114122","messageId":"cd3664ac0905162107t7ebca943p1722685a8484f08e@mail.gmail.com","threadId":"19354","inReplyTo":"7vzldclt33.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Fix minor memory leak in init-db","fromName":"Ammon Riley","fromEmail":"ammon.riley@gmail.com","sentAt":"2009-05-17T04:07:40Z","receivedAt":"2009-05-17T04:07:40Z","isPatch":true,"sender":{"key":"ammon.riley@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1801261?v=4"},"body":"On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ammon Riley <ammon.riley@gmail.com> writes:\n>\n>> There was an xmalloc() for path, but I didn't see a corresponding free().\n>> Does it happen somewhere else that I'm not expecting?\n>\n> It implicitly happens in exit() in git.c:handle_internal_command()\n> after cmd_init_db() returns the control to it.\n\nAh. Naturally. :)\n\nSo if I were to write a long-lived application (such as a custom UI) that\nlinks to libgit, and bypasses those functions to call init_db() (and other\nfunctions) directly, all those implicit free-on-exit() turn into memory\nleaks.\n\nCheers,\nAmmon\n"},{"id":"114123","messageId":"7veiuojoqy.fsf@alter.siamese.dyndns.org","threadId":"19354","inReplyTo":"cd3664ac0905162107t7ebca943p1722685a8484f08e@mail.gmail.com","subject":"Re: [PATCH] Fix minor memory leak in init-db","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-17T05:13:25Z","receivedAt":"2009-05-17T05:13:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ammon Riley <ammon.riley@gmail.com> writes:\n\n> On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Ammon Riley <ammon.riley@gmail.com> writes:\n>>\n>>> There was an xmalloc() for path, but I didn't see a corresponding free().\n>>> Does it happen somewhere else that I'm not expecting?\n>>\n>> It implicitly happens in exit() in git.c:handle_internal_command()\n>> after cmd_init_db() returns the control to it.\n>\n> Ah. Naturally. :)\n>\n> So if I were to write a long-lived application (such as a custom UI) that\n> links to libgit, and bypasses those functions to call init_db() (and other\n> functions) directly, all those implicit free-on-exit() turn into memory\n> leaks.\n\nCorrect, and there are other much larger issues to worry about.\n\nThat's why there is a separate libgit2 effort in progress.\n"},{"id":"114136","messageId":"cd3664ac0905170909l3184c286s7f7d61e108fd5b05@mail.gmail.com","threadId":"19354","inReplyTo":"7veiuojoqy.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Fix minor memory leak in init-db","fromName":"Ammon Riley","fromEmail":"ammon.riley@gmail.com","sentAt":"2009-05-17T16:09:17Z","receivedAt":"2009-05-17T16:09:17Z","isPatch":true,"sender":{"key":"ammon.riley@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1801261?v=4"},"body":"On Sat, May 16, 2009 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ammon Riley <ammon.riley@gmail.com> writes:\n>\n>> On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>> Ammon Riley <ammon.riley@gmail.com> writes:\n>>>\n>>>> There was an xmalloc() for path, but I didn't see a corresponding free().\n>>>> Does it happen somewhere else that I'm not expecting?\n>>>\n>>> It implicitly happens in exit() in git.c:handle_internal_command()\n>>> after cmd_init_db() returns the control to it.\n>>\n>> Ah. Naturally. :)\n>>\n>> So if I were to write a long-lived application (such as a custom UI) that\n>> links to libgit, and bypasses those functions to call init_db() (and other\n>> functions) directly, all those implicit free-on-exit() turn into memory\n>> leaks.\n>\n> Correct, and there are other much larger issues to worry about.\n>\n> That's why there is a separate libgit2 effort in progress.\n\nOkay, cool! I wasn't aware of that -- I'll take a look at it. In the meantime,\nare small patches for this type of issue welcome if I run across others,\nor would you prefer I let them lie?\n\nCheers,\nAmmon\n"}]}