git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Re: [PATCH] maintenance: fix two memory leaks

From
Llilinchao@oschina.cn <lilinchao@oschina.cn>
Date
May 10, 2021, 07:50 UTC
Message-ID
<5abbc3beb16411eba07a0024e87935e7@oschina.cn>
In-Reply-To
<0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com>
Show 43 quoted lines
>"lilinchao@oschina.cn" <lilinchao@oschina.cn> writes:
>
>>>@@ -1999,6 +2000,7 @@ static int update_background_schedule(int enable)
>>> die("unknown background scheduler: %s", scheduler);
>>>
>>> rollback_lock_file(&lk);
>>>+	free(lock_path);
>> Based on your change, I think when "hold_lock_file_for_update()<0", we should also free local_path
>> Thanks
>
>Meaning something like this?
>
>
> builtin/gc.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git c/builtin/gc.c w/builtin/gc.c
>index 98a803196b..50565c37c7 100644
>--- c/builtin/gc.c
>+++ w/builtin/gc.c
>@@ -1971,8 +1971,10 @@ static int update_background_schedule(int enable)
> cmd = sep + 1;
> }
>
>-	if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0)
>-	return error(_("another process is scheduling background maintenance"));
>+	if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
>+	result = error(_("another process is scheduling background maintenance"));
>+	goto cleanup;
>+	}
>
> if (!strcmp(scheduler, "launchctl"))
> result = launchctl_update_schedule(enable, get_lock_file_fd(&lk), cmd);
>@@ -1984,6 +1986,9 @@ static int update_background_schedule(int enable)
> die("unknown background scheduler: %s", scheduler);
>
> rollback_lock_file(&lk);
>+
>+cleanup:
>+	free(lock_path);
> free(testing);
> return result;
> }

Yes, it's almost like this, and your is better than I thought. I just referred to this function(L1266-L1321):

static int maintenance_run_tasks(struct maintenance_run_opts *opts)
{
        ...
if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
                ...

free(lock_path); return 0; } free(lock_path);

        ...
        ...

rollback_lock_file(&lk); return result; }

and thought we should also apply it to "update_background_schedule()".
Previous: Junio C Hamano
Message 9 of 9 in “maintenance: fix two memory leaks”
  1. maintenance: fix two memory leaksLénaïc Huard, May 9, 2021
  2. Junio C HamanoMay 10, 2021
  3. lilinchao@oschina.cnMay 10, 2021
  4. Junio C HamanoMay 10, 2021
  5. 0/1 maintenance: fix two memory leaksLénaïc Huard, May 10, 2021
  6. 1/1 maintenance: fix two memory leaksLénaïc Huard, May 10, 2021
  7. Derrick StoleeMay 11, 2021
  8. Junio C HamanoMay 11, 2021
  9. lilinchao@oschina.cnMay 10, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.