Re: [PATCH] maintenance: fix two memory leaks
From: Junio C Hamano <hidden>
Date: 2021-05-10 06:34:21
Lénaïc Huard [off-list ref] 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.
quoted hunk
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.
quoted hunk
@@ -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.