git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] maintenance: fix two memory leaks
@ 2021-05-09 22:16 Lénaïc Huard
  2021-05-10  6:34 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Lénaïc Huard @ 2021-05-09 22:16 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Derrick Stolee, Eric Sunshine, Lénaïc Huard

Fixes two memory leaks when running `git maintenance start` or `git
maintenance stop` in `update_background_schedule`:

$ valgrind --leak-check=full ~/git/bin/git maintenance start
==76584== Memcheck, a memory error detector
==76584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==76584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==76584== Command: /home/lenaic/git/bin/git maintenance start
==76584==
==76584==
==76584== HEAP SUMMARY:
==76584==     in use at exit: 34,880 bytes in 252 blocks
==76584==   total heap usage: 820 allocs, 568 frees, 146,414 bytes allocated
==76584==
==76584== 65 bytes in 1 blocks are definitely lost in loss record 17 of 39
==76584==    at 0x483E6AF: malloc (vg_replace_malloc.c:306)
==76584==    by 0x3DC39C: xrealloc (wrapper.c:126)
==76584==    by 0x3992CC: strbuf_grow (strbuf.c:98)
==76584==    by 0x39A473: strbuf_vaddf (strbuf.c:392)
==76584==    by 0x39BC54: xstrvfmt (strbuf.c:979)
==76584==    by 0x39BD2C: xstrfmt (strbuf.c:989)
==76584==    by 0x18451B: update_background_schedule (gc.c:1977)
==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
==76584==    by 0x127A2E: run_builtin (git.c:453)
==76584==    by 0x127E81: handle_builtin (git.c:704)
==76584==    by 0x128142: run_argv (git.c:771)
==76584==
==76584== 240 bytes in 1 blocks are definitely lost in loss record 29 of 39
==76584==    at 0x4840D7B: realloc (vg_replace_malloc.c:834)
==76584==    by 0x491CE5D: getdelim (in /usr/lib/libc-2.33.so)
==76584==    by 0x39ADD7: strbuf_getwholeline (strbuf.c:635)
==76584==    by 0x39AF31: strbuf_getdelim (strbuf.c:706)
==76584==    by 0x39B064: strbuf_getline_lf (strbuf.c:727)
==76584==    by 0x184273: crontab_update_schedule (gc.c:1919)
==76584==    by 0x184678: update_background_schedule (gc.c:1997)
==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
==76584==    by 0x127A2E: run_builtin (git.c:453)
==76584==    by 0x127E81: handle_builtin (git.c:704)
==76584==    by 0x128142: run_argv (git.c:771)
==76584==
==76584== LEAK SUMMARY:
==76584==    definitely lost: 305 bytes in 2 blocks
==76584==    indirectly lost: 0 bytes in 0 blocks
==76584==      possibly lost: 0 bytes in 0 blocks
==76584==    still reachable: 34,575 bytes in 250 blocks
==76584==         suppressed: 0 bytes in 0 blocks
==76584== Reachable blocks (those to which a pointer was found) are not shown.
==76584== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==76584==
==76584== For lists of detected and suppressed errors, rerun with: -s
==76584== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr>
---
 builtin/gc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/builtin/gc.c b/builtin/gc.c
index ef7226d7bc..2574068ae2 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1947,6 +1947,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
 		fprintf(cron_in, "\n%s\n", END_LINE);
 	}
 
+	strbuf_release(&line);
 	fflush(cron_in);
 	fclose(cron_in);
 	close(crontab_edit.in);
@@ -1999,6 +2000,7 @@ static int update_background_schedule(int enable)
 		die("unknown background scheduler: %s", scheduler);
 
 	rollback_lock_file(&lk);
+	free(lock_path);
 	free(testing);
 	return result;
 }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] maintenance: fix two memory leaks
  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 19:59 ` [PATCH v2 0/1] " Lénaïc Huard
  2 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2021-05-10  6:34 UTC (permalink / raw)
  To: Lénaïc Huard; +Cc: git, Derrick Stolee, Eric Sunshine

Lénaïc Huard <lenaic@lhuard.fr> writes:

> Fixes two memory leaks when running `git maintenance start` or `git
> maintenance stop` in `update_background_schedule`:

Thanks, both places look correct, but I have one minor "hmph"
comment.

> diff --git a/builtin/gc.c b/builtin/gc.c
> index ef7226d7bc..2574068ae2 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1947,6 +1947,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
>  		fprintf(cron_in, "\n%s\n", END_LINE);
>  	}
>  
> +	strbuf_release(&line);
>  	fflush(cron_in);
>  	fclose(cron_in);
>  	close(crontab_edit.in);

This is somewhat a curious placement---the loop that iterates over
the cron_list FILE with "while (!strbuf_getline_lf(&line, cron_list)"
is the only place the list strbuf is used, and I wonder if it makes
more sense to do this immediately after the loop.

> @@ -1999,6 +2000,7 @@ static int update_background_schedule(int enable)
>  		die("unknown background scheduler: %s", scheduler);
>  
>  	rollback_lock_file(&lk);
> +	free(lock_path);
>  	free(testing);
>  	return result;
>  }

This one looks quite natural.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] maintenance: fix two memory leaks
  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 19:59 ` [PATCH v2 0/1] " Lénaïc Huard
  2 siblings, 2 replies; 9+ messages in thread
From: lilinchao @ 2021-05-10  6:38 UTC (permalink / raw)
  To: Lénaïc Huard, git
  Cc: Junio C Hamano, Derrick Stolee, Eric Sunshine, Lénaïc Huard

Hi,

>Fixes two memory leaks when running `git maintenance start` or `git
>maintenance stop` in `update_background_schedule`:
>
>$ valgrind --leak-check=full ~/git/bin/git maintenance start
>==76584== Memcheck, a memory error detector
>==76584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
>==76584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
>==76584== Command: /home/lenaic/git/bin/git maintenance start
>==76584==
>==76584==
>==76584== HEAP SUMMARY:
>==76584==     in use at exit: 34,880 bytes in 252 blocks
>==76584==   total heap usage: 820 allocs, 568 frees, 146,414 bytes allocated
>==76584==
>==76584== 65 bytes in 1 blocks are definitely lost in loss record 17 of 39
>==76584==    at 0x483E6AF: malloc (vg_replace_malloc.c:306)
>==76584==    by 0x3DC39C: xrealloc (wrapper.c:126)
>==76584==    by 0x3992CC: strbuf_grow (strbuf.c:98)
>==76584==    by 0x39A473: strbuf_vaddf (strbuf.c:392)
>==76584==    by 0x39BC54: xstrvfmt (strbuf.c:979)
>==76584==    by 0x39BD2C: xstrfmt (strbuf.c:989)
>==76584==    by 0x18451B: update_background_schedule (gc.c:1977)
>==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
>==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
>==76584==    by 0x127A2E: run_builtin (git.c:453)
>==76584==    by 0x127E81: handle_builtin (git.c:704)
>==76584==    by 0x128142: run_argv (git.c:771)
>==76584==
>==76584== 240 bytes in 1 blocks are definitely lost in loss record 29 of 39
>==76584==    at 0x4840D7B: realloc (vg_replace_malloc.c:834)
>==76584==    by 0x491CE5D: getdelim (in /usr/lib/libc-2.33.so)
>==76584==    by 0x39ADD7: strbuf_getwholeline (strbuf.c:635)
>==76584==    by 0x39AF31: strbuf_getdelim (strbuf.c:706)
>==76584==    by 0x39B064: strbuf_getline_lf (strbuf.c:727)
>==76584==    by 0x184273: crontab_update_schedule (gc.c:1919)
>==76584==    by 0x184678: update_background_schedule (gc.c:1997)
>==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
>==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
>==76584==    by 0x127A2E: run_builtin (git.c:453)
>==76584==    by 0x127E81: handle_builtin (git.c:704)
>==76584==    by 0x128142: run_argv (git.c:771)
>==76584==
>==76584== LEAK SUMMARY:
>==76584==    definitely lost: 305 bytes in 2 blocks
>==76584==    indirectly lost: 0 bytes in 0 blocks
>==76584==      possibly lost: 0 bytes in 0 blocks
>==76584==    still reachable: 34,575 bytes in 250 blocks
>==76584==         suppressed: 0 bytes in 0 blocks
>==76584== Reachable blocks (those to which a pointer was found) are not shown.
>==76584== To see them, rerun with: --leak-check=full --show-leak-kinds=all
>==76584==
>==76584== For lists of detected and suppressed errors, rerun with: -s
>==76584== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
>
>Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr>
>---
> builtin/gc.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/builtin/gc.c b/builtin/gc.c
>index ef7226d7bc..2574068ae2 100644
>--- a/builtin/gc.c
>+++ b/builtin/gc.c
>@@ -1947,6 +1947,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
> fprintf(cron_in, "\n%s\n", END_LINE);
> }
>
>+	strbuf_release(&line); 
> fflush(cron_in);
> fclose(cron_in);
> close(crontab_edit.in);
>@@ -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

> free(testing);
> return result;
> }
>--
>2.31.1
>
> 

Thanks

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] maintenance: fix two memory leaks
  2021-05-10  6:38 ` lilinchao
@ 2021-05-10  7:11   ` Junio C Hamano
       [not found]   ` <0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com>
  1 sibling, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2021-05-10  7:11 UTC (permalink / raw)
  To: lilinchao; +Cc: Lénaïc Huard, git, Derrick Stolee, Eric Sunshine

"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;
 }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Re: [PATCH] maintenance: fix two memory leaks
       [not found]   ` <0c04f7c2b15f11eb82baa4badb2c2b1178978@pobox.com>
@ 2021-05-10  7:50     ` lilinchao
  0 siblings, 0 replies; 9+ messages in thread
From: lilinchao @ 2021-05-10  7:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Lénaïc Huard, git, Derrick Stolee, Eric Sunshine

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 0/1] maintenance: fix two memory leaks
  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 19:59 ` Lénaïc Huard
  2021-05-10 19:59   ` [PATCH v2 1/1] " Lénaïc Huard
  2021-05-11  3:29   ` [PATCH v2 0/1] " Junio C Hamano
  2 siblings, 2 replies; 9+ messages in thread
From: Lénaïc Huard @ 2021-05-10 19:59 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Eric Sunshine, lilinchao,
	Lénaïc Huard

Hi!

Thank you for the code review.

I’ve moved the `strbuf_release(&line);` closer to the last point where
`line` is used.

And I’ve included Junio’s patch to address the missing
`free(local_path)` when `hold_lock_file_for_update()<0`.

Lénaïc Huard (1):
  maintenance: fix two memory leaks

 builtin/gc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/1] maintenance: fix two memory leaks
  2021-05-10 19:59 ` [PATCH v2 0/1] " Lénaïc Huard
@ 2021-05-10 19:59   ` Lénaïc Huard
  2021-05-11 15:13     ` Derrick Stolee
  2021-05-11  3:29   ` [PATCH v2 0/1] " Junio C Hamano
  1 sibling, 1 reply; 9+ messages in thread
From: Lénaïc Huard @ 2021-05-10 19:59 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Eric Sunshine, lilinchao,
	Lénaïc Huard

Fixes two memory leaks when running `git maintenance start` or `git
maintenance stop` in `update_background_schedule`:

$ valgrind --leak-check=full ~/git/bin/git maintenance start
==76584== Memcheck, a memory error detector
==76584== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==76584== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==76584== Command: /home/lenaic/git/bin/git maintenance start
==76584==
==76584==
==76584== HEAP SUMMARY:
==76584==     in use at exit: 34,880 bytes in 252 blocks
==76584==   total heap usage: 820 allocs, 568 frees, 146,414 bytes allocated
==76584==
==76584== 65 bytes in 1 blocks are definitely lost in loss record 17 of 39
==76584==    at 0x483E6AF: malloc (vg_replace_malloc.c:306)
==76584==    by 0x3DC39C: xrealloc (wrapper.c:126)
==76584==    by 0x3992CC: strbuf_grow (strbuf.c:98)
==76584==    by 0x39A473: strbuf_vaddf (strbuf.c:392)
==76584==    by 0x39BC54: xstrvfmt (strbuf.c:979)
==76584==    by 0x39BD2C: xstrfmt (strbuf.c:989)
==76584==    by 0x18451B: update_background_schedule (gc.c:1977)
==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
==76584==    by 0x127A2E: run_builtin (git.c:453)
==76584==    by 0x127E81: handle_builtin (git.c:704)
==76584==    by 0x128142: run_argv (git.c:771)
==76584==
==76584== 240 bytes in 1 blocks are definitely lost in loss record 29 of 39
==76584==    at 0x4840D7B: realloc (vg_replace_malloc.c:834)
==76584==    by 0x491CE5D: getdelim (in /usr/lib/libc-2.33.so)
==76584==    by 0x39ADD7: strbuf_getwholeline (strbuf.c:635)
==76584==    by 0x39AF31: strbuf_getdelim (strbuf.c:706)
==76584==    by 0x39B064: strbuf_getline_lf (strbuf.c:727)
==76584==    by 0x184273: crontab_update_schedule (gc.c:1919)
==76584==    by 0x184678: update_background_schedule (gc.c:1997)
==76584==    by 0x1846F6: maintenance_start (gc.c:2011)
==76584==    by 0x1847B4: cmd_maintenance (gc.c:2030)
==76584==    by 0x127A2E: run_builtin (git.c:453)
==76584==    by 0x127E81: handle_builtin (git.c:704)
==76584==    by 0x128142: run_argv (git.c:771)
==76584==
==76584== LEAK SUMMARY:
==76584==    definitely lost: 305 bytes in 2 blocks
==76584==    indirectly lost: 0 bytes in 0 blocks
==76584==      possibly lost: 0 bytes in 0 blocks
==76584==    still reachable: 34,575 bytes in 250 blocks
==76584==         suppressed: 0 bytes in 0 blocks
==76584== Reachable blocks (those to which a pointer was found) are not shown.
==76584== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==76584==
==76584== For lists of detected and suppressed errors, rerun with: -s
==76584== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr>
---
 builtin/gc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index ef7226d7bc..484fe983d3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1924,6 +1924,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
 		else if (!in_old_region)
 			fprintf(cron_in, "%s\n", line.buf);
 	}
+	strbuf_release(&line);
 
 	if (run_maintenance) {
 		struct strbuf line_format = STRBUF_INIT;
@@ -1986,8 +1987,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);
@@ -1999,6 +2002,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;
 }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/1] maintenance: fix two memory leaks
  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  3:29   ` Junio C Hamano
  1 sibling, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2021-05-11  3:29 UTC (permalink / raw)
  To: Lénaïc Huard; +Cc: git, Derrick Stolee, Eric Sunshine, lilinchao

Lénaïc Huard <lenaic@lhuard.fr> writes:

> Hi!
>
> Thank you for the code review.
>
> I’ve moved the `strbuf_release(&line);` closer to the last point where
> `line` is used.
>
> And I’ve included Junio’s patch to address the missing
> `free(local_path)` when `hold_lock_file_for_update()<0`.
>
> Lénaïc Huard (1):
>   maintenance: fix two memory leaks
>
>  builtin/gc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Thanks, will queue.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/1] maintenance: fix two memory leaks
  2021-05-10 19:59   ` [PATCH v2 1/1] " Lénaïc Huard
@ 2021-05-11 15:13     ` Derrick Stolee
  0 siblings, 0 replies; 9+ messages in thread
From: Derrick Stolee @ 2021-05-11 15:13 UTC (permalink / raw)
  To: Lénaïc Huard, git
  Cc: Junio C Hamano, Derrick Stolee, Eric Sunshine, lilinchao

On 5/10/2021 3:59 PM, Lénaïc Huard wrote:
> Fixes two memory leaks when running `git maintenance start` or `git
> maintenance stop` in `update_background_schedule`:

Thanks for finding these leaks.

> ---
>  builtin/gc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/gc.c b/builtin/gc.c
> index ef7226d7bc..484fe983d3 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1924,6 +1924,7 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd)
>  		else if (!in_old_region)
>  			fprintf(cron_in, "%s\n", line.buf);
>  	}
> +	strbuf_release(&line);
>  
>  	if (run_maintenance) {
>  		struct strbuf line_format = STRBUF_INIT;
> @@ -1986,8 +1987,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);
> @@ -1999,6 +2002,9 @@ static int update_background_schedule(int enable)
>  		die("unknown background scheduler: %s", scheduler);
>  
>  	rollback_lock_file(&lk);
> +
> +cleanup:
> +	free(lock_path);

And I agree that this version looks good. 

Thanks,
-Stolee

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-11 15:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git