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

From: Junio C Hamano <[email-masked]>
Date: Mon, 10 May 2021 15:34:18 +0900

Lénaïc Huard <[email-masked]> 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.