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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>"lilinchao@xxxxxxxxxx" <lilinchao@xxxxxxxxxx> 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()".






[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux