summaryrefslogtreecommitdiff
path: root/builtin/commit.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-06-11 11:19:22 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-11 13:15:04 -0700
commit14da26230a7644a2f9dfbc3f43d9d7ab6e0074e9 (patch)
tree600341b6864236888a6508a79bf46e97436ded8b /builtin/commit.c
parent56931c4d89e7efe41dd96d230b8176e2d32a035d (diff)
parse-options: fix leaks for users of OPT_FILENAME
The `OPT_FILENAME()` option will, if set, put an allocated string into the user-provided variable. Consequently, that variable thus needs to be free'd by the caller of `parse_options()`. Some callsites don't though and thus leak memory. Fix those. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/commit.c')
-rw-r--r--builtin/commit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/commit.c b/builtin/commit.c
index f53e7e86ff..dcaf4efa03 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -106,7 +106,8 @@ static enum {
COMMIT_PARTIAL
} commit_style;
-static const char *logfile, *force_author;
+static const char *force_author;
+static char *logfile;
static char *template_file;
/*
* The _message variables are commit names from which to take
@@ -1309,7 +1310,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
!!use_message, "-C",
!!logfile, "-F");
if (use_message || edit_message || logfile ||fixup_message || have_option_m)
- template_file = NULL;
+ FREE_AND_NULL(template_file);
if (edit_message)
use_message = edit_message;
if (amend && !use_message && !fixup_message)
@@ -1892,5 +1893,7 @@ cleanup:
strbuf_release(&author_ident);
strbuf_release(&err);
strbuf_release(&sb);
+ free(logfile);
+ free(template_file);
return ret;
}