Re: [PATCH] maintenance: fix two memory leaks
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 10, 2021, 06:34 UTC
- Message-ID
- <xmqqpmxzqeqd.fsf@gitster.g>
- In-Reply-To
- <20210509221613.474887-1-lenaic@lhuard.fr>
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.
Show 12 quoted lines
> 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.
Show 8 quoted lines
> @@ -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.