diff: fix leaking orderfile option
The `orderfile` diff option is being assigned via `OPT_FILENAME()`, which assigns an allocated string to the variable. We never free it though, causing a memory leak. Change the type of the string to `char *` and free it to plug the leak. This also requires us to use `xstrdup()` to assign the global config to it in case it is set. This leak is being hit in t7621, but plugging it alone does not make the test suite pass. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
49af1b7722
commit
76c7e708bb
|
@ -1393,9 +1393,8 @@ static struct combine_diff_path *find_paths_generic(const struct object_id *oid,
|
||||||
{
|
{
|
||||||
struct combine_diff_path *paths = NULL;
|
struct combine_diff_path *paths = NULL;
|
||||||
int i, num_parent = parents->nr;
|
int i, num_parent = parents->nr;
|
||||||
|
|
||||||
int output_format = opt->output_format;
|
int output_format = opt->output_format;
|
||||||
const char *orderfile = opt->orderfile;
|
char *orderfile = opt->orderfile;
|
||||||
|
|
||||||
opt->output_format = DIFF_FORMAT_NO_OUTPUT;
|
opt->output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||||
/* tell diff_tree to emit paths in sorted (=tree) order */
|
/* tell diff_tree to emit paths in sorted (=tree) order */
|
||||||
|
|
7
diff.c
7
diff.c
|
@ -441,8 +441,10 @@ int git_diff_ui_config(const char *var, const char *value,
|
||||||
}
|
}
|
||||||
if (!strcmp(var, "diff.wordregex"))
|
if (!strcmp(var, "diff.wordregex"))
|
||||||
return git_config_string(&diff_word_regex_cfg, var, value);
|
return git_config_string(&diff_word_regex_cfg, var, value);
|
||||||
if (!strcmp(var, "diff.orderfile"))
|
if (!strcmp(var, "diff.orderfile")) {
|
||||||
|
FREE_AND_NULL(diff_order_file_cfg);
|
||||||
return git_config_pathname(&diff_order_file_cfg, var, value);
|
return git_config_pathname(&diff_order_file_cfg, var, value);
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcmp(var, "diff.ignoresubmodules")) {
|
if (!strcmp(var, "diff.ignoresubmodules")) {
|
||||||
if (!value)
|
if (!value)
|
||||||
|
@ -4775,7 +4777,7 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
|
||||||
if (diff_indent_heuristic)
|
if (diff_indent_heuristic)
|
||||||
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
DIFF_XDL_SET(options, INDENT_HEURISTIC);
|
||||||
|
|
||||||
options->orderfile = diff_order_file_cfg;
|
options->orderfile = xstrdup_or_null(diff_order_file_cfg);
|
||||||
|
|
||||||
if (!options->flags.ignore_submodule_set)
|
if (!options->flags.ignore_submodule_set)
|
||||||
options->flags.ignore_untracked_in_submodules = 1;
|
options->flags.ignore_untracked_in_submodules = 1;
|
||||||
|
@ -6727,6 +6729,7 @@ void diff_free(struct diff_options *options)
|
||||||
FREE_AND_NULL(options->objfind);
|
FREE_AND_NULL(options->objfind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREE_AND_NULL(options->orderfile);
|
||||||
for (size_t i = 0; i < options->anchors_nr; i++)
|
for (size_t i = 0; i < options->anchors_nr; i++)
|
||||||
free(options->anchors[i]);
|
free(options->anchors[i]);
|
||||||
FREE_AND_NULL(options->anchors);
|
FREE_AND_NULL(options->anchors);
|
||||||
|
|
2
diff.h
2
diff.h
|
@ -235,7 +235,7 @@ enum diff_submodule_format {
|
||||||
* diffcore library with.
|
* diffcore library with.
|
||||||
*/
|
*/
|
||||||
struct diff_options {
|
struct diff_options {
|
||||||
const char *orderfile;
|
char *orderfile;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "--rotate-to=<file>" would start showing at <file> and when
|
* "--rotate-to=<file>" would start showing at <file> and when
|
||||||
|
|
Loading…
Reference in New Issue