From: "lilinchao@oschina.cn" <lilinchao@oschina.cn>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: "Lénaïc Huard" <lenaic@lhuard.fr>, git <git@vger.kernel.org>,
"Derrick Stolee" <dstolee@microsoft.com>,
"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: Re: [PATCH] maintenance: fix two memory leaks
Date: Mon, 10 May 2021 15:50:08 +0800 [thread overview]
Message-ID: <5abbc3beb16411eba07a0024e87935e7@oschina.cn> (raw)
In-Reply-To: 0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com
>"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()".
next prev parent reply other threads:[~2021-05-10 7:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-09 22:16 [PATCH] maintenance: fix two memory leaks Lénaïc Huard
2021-05-10 6:34 ` Junio C Hamano
2021-05-10 6:38 ` lilinchao
2021-05-10 7:11 ` Junio C Hamano
[not found] ` <0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com>
2021-05-10 7:50 ` lilinchao [this message]
2021-05-10 19:59 ` [PATCH v2 0/1] " Lénaïc Huard
2021-05-10 19:59 ` [PATCH v2 1/1] " Lénaïc Huard
2021-05-11 15:13 ` Derrick Stolee
2021-05-11 3:29 ` [PATCH v2 0/1] " Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2021-05-10 11:47 Re: [PATCH] " Оксана Алексеева
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5abbc3beb16411eba07a0024e87935e7@oschina.cn \
--to=lilinchao@oschina.cn \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=lenaic@lhuard.fr \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).