* [PATCH] Fix minor memory leak in init-db
@ 2009-05-14 22:22 Ammon Riley
2009-05-16 19:56 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Ammon Riley @ 2009-05-14 22:22 UTC (permalink / raw)
To: git
There was an xmalloc() for path, but I didn't see a corresponding free().
Does it happen somewhere else that I'm not expecting?
Signed-off-by: Ammon Riley <ammon.riley@gmail.com>
---
builtin-init-db.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index d1fa12a..6969987 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -308,6 +308,8 @@ int init_db(const char *template_dir, unsigned int flags)
strcpy(path+len, "/info");
safe_create_dir(path, 1);
+ free(path);
+
if (shared_repository) {
char buf[10];
/* We do not spell "group" and such, so that
--
1.6.3.1.9.g95405b.dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] Fix minor memory leak in init-db
2009-05-14 22:22 [PATCH] Fix minor memory leak in init-db Ammon Riley
@ 2009-05-16 19:56 ` Junio C Hamano
2009-05-17 4:07 ` Ammon Riley
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-05-16 19:56 UTC (permalink / raw)
To: Ammon Riley; +Cc: git
Ammon Riley <ammon.riley@gmail.com> writes:
> There was an xmalloc() for path, but I didn't see a corresponding free().
> Does it happen somewhere else that I'm not expecting?
It implicitly happens in exit() in git.c:handle_internal_command()
after cmd_init_db() returns the control to it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix minor memory leak in init-db
2009-05-16 19:56 ` Junio C Hamano
@ 2009-05-17 4:07 ` Ammon Riley
2009-05-17 5:13 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Ammon Riley @ 2009-05-17 4:07 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ammon Riley <ammon.riley@gmail.com> writes:
>
>> There was an xmalloc() for path, but I didn't see a corresponding free().
>> Does it happen somewhere else that I'm not expecting?
>
> It implicitly happens in exit() in git.c:handle_internal_command()
> after cmd_init_db() returns the control to it.
Ah. Naturally. :)
So if I were to write a long-lived application (such as a custom UI) that
links to libgit, and bypasses those functions to call init_db() (and other
functions) directly, all those implicit free-on-exit() turn into memory
leaks.
Cheers,
Ammon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix minor memory leak in init-db
2009-05-17 4:07 ` Ammon Riley
@ 2009-05-17 5:13 ` Junio C Hamano
2009-05-17 16:09 ` Ammon Riley
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-05-17 5:13 UTC (permalink / raw)
To: Ammon Riley; +Cc: Junio C Hamano, git
Ammon Riley <ammon.riley@gmail.com> writes:
> On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Ammon Riley <ammon.riley@gmail.com> writes:
>>
>>> There was an xmalloc() for path, but I didn't see a corresponding free().
>>> Does it happen somewhere else that I'm not expecting?
>>
>> It implicitly happens in exit() in git.c:handle_internal_command()
>> after cmd_init_db() returns the control to it.
>
> Ah. Naturally. :)
>
> So if I were to write a long-lived application (such as a custom UI) that
> links to libgit, and bypasses those functions to call init_db() (and other
> functions) directly, all those implicit free-on-exit() turn into memory
> leaks.
Correct, and there are other much larger issues to worry about.
That's why there is a separate libgit2 effort in progress.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix minor memory leak in init-db
2009-05-17 5:13 ` Junio C Hamano
@ 2009-05-17 16:09 ` Ammon Riley
0 siblings, 0 replies; 5+ messages in thread
From: Ammon Riley @ 2009-05-17 16:09 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Sat, May 16, 2009 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ammon Riley <ammon.riley@gmail.com> writes:
>
>> On Sat, May 16, 2009 at 12:56 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Ammon Riley <ammon.riley@gmail.com> writes:
>>>
>>>> There was an xmalloc() for path, but I didn't see a corresponding free().
>>>> Does it happen somewhere else that I'm not expecting?
>>>
>>> It implicitly happens in exit() in git.c:handle_internal_command()
>>> after cmd_init_db() returns the control to it.
>>
>> Ah. Naturally. :)
>>
>> So if I were to write a long-lived application (such as a custom UI) that
>> links to libgit, and bypasses those functions to call init_db() (and other
>> functions) directly, all those implicit free-on-exit() turn into memory
>> leaks.
>
> Correct, and there are other much larger issues to worry about.
>
> That's why there is a separate libgit2 effort in progress.
Okay, cool! I wasn't aware of that -- I'll take a look at it. In the meantime,
are small patches for this type of issue welcome if I run across others,
or would you prefer I let them lie?
Cheers,
Ammon
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-05-17 16:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-14 22:22 [PATCH] Fix minor memory leak in init-db Ammon Riley
2009-05-16 19:56 ` Junio C Hamano
2009-05-17 4:07 ` Ammon Riley
2009-05-17 5:13 ` Junio C Hamano
2009-05-17 16:09 ` Ammon Riley
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).