aboutsummaryrefslogtreecommitdiffstats
path: root/parse-options.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:25 -0700
committerJunio C Hamano <gitster@pobox.com>2024-10-02 07:46:26 -0700
commit365529e1ea19b44a7a253b780f3ae3a1cb2f081f (patch)
tree5a34837f74d165858246b1dd9706b926d7a998e5 /parse-options.c
parentMerge branch 'ds/sparse-checkout-expansion-advice' (diff)
parentdiffcore-break: fix leaking filespecs when merging broken pairs (diff)
downloadgit-365529e1ea19b44a7a253b780f3ae3a1cb2f081f.tar.gz
git-365529e1ea19b44a7a253b780f3ae3a1cb2f081f.zip
Merge branch 'ps/leakfixes-part-7'
More leak-fixes. * ps/leakfixes-part-7: (23 commits) diffcore-break: fix leaking filespecs when merging broken pairs revision: fix leaking parents when simplifying commits builtin/maintenance: fix leak in `get_schedule_cmd()` builtin/maintenance: fix leaking config string promisor-remote: fix leaking partial clone filter grep: fix leaking grep pattern submodule: fix leaking submodule ODB paths trace2: destroy context stored in thread-local storage builtin/difftool: plug several trivial memory leaks builtin/repack: fix leaking configuration diffcore-order: fix leaking buffer when parsing orderfiles parse-options: free previous value of `OPTION_FILENAME` diff: fix leaking orderfile option builtin/pull: fix leaking "ff" option dir: fix off by one errors for ignored and untracked entries builtin/submodule--helper: fix leaking remote ref on errors t/helper: fix leaking subrepo in nested submodule config helper builtin/submodule--helper: fix leaking error buffer builtin/submodule--helper: clear child process when not running it submodule: fix leaking update strategy ...
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/parse-options.c b/parse-options.c
index 30b9e68f8a..33bfba0ed4 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -60,12 +60,12 @@ static enum parse_opt_result get_arg(struct parse_opt_ctx_t *p,
return 0;
}
-static void fix_filename(const char *prefix, char **file)
+static char *fix_filename(const char *prefix, const char *file)
{
if (!file || !*file)
- ; /* leave as NULL */
+ return NULL;
else
- *file = prefix_filename_except_for_dash(prefix, *file);
+ return prefix_filename_except_for_dash(prefix, file);
}
static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
@@ -129,18 +129,24 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
return 0;
case OPTION_FILENAME:
+ {
+ const char *value;
+
+ FREE_AND_NULL(*(char **)opt->value);
+
err = 0;
+
if (unset)
- *(const char **)opt->value = NULL;
+ value = NULL;
else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
- *(const char **)opt->value = (const char *)opt->defval;
+ value = (const char *) opt->defval;
else
- err = get_arg(p, opt, flags, (const char **)opt->value);
+ err = get_arg(p, opt, flags, &value);
if (!err)
- fix_filename(p->prefix, (char **)opt->value);
+ *(char **)opt->value = fix_filename(p->prefix, value);
return err;
-
+ }
case OPTION_CALLBACK:
{
const char *p_arg = NULL;