diff: remove parseopts member from struct diff_options

repo_diff_setup() builds the struct option array with git diff's command line options and stores a pointer to it in the parseopts member of struct diff_options. The array is freed by diff_setup_done(), but not by release_revisions(). Thus calling only repo_diff_setup() and release_revisions() leaks that array. We could free it in release_revisions() as well to plug that leak, but there is a better way: Only build it when needed. Absorb prep_parse_options() into the last place that uses the parseopts member of struct diff_options, add_diff_parseopts(), and get rid of said member. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 1, 2022 at 23:53 UTC 189e97bc4ba8d5f2ab4746d41204feed159fbe9a
2 files changed +1 -15
diff.c
+1 -14
@@ -4593,8 +4593,6 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
4593 builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
4594 }
4595
4596 -static void prep_parse_options(struct diff_options *options);
4597 -
4596 void repo_diff_setup(struct repository *r, struct diff_options *options)
4597 {
4598 memcpy(options, &default_diff_options, sizeof(*options));
@@ -4640,8 +4638,6 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
4638
4639 options->color_moved = diff_color_moved_default;
4640 options->color_moved_ws_handling = diff_color_moved_ws_default;
4643 -
4644 - prep_parse_options(options);
4641 }
4642
4643 static const char diff_status_letters[] = {
@@ -4799,8 +4795,6 @@ void diff_setup_done(struct diff_options *options)
4795 options->filter = ~filter_bit[DIFF_STATUS_FILTER_AON];
4796 options->filter &= ~options->filter_not;
4797 }
4802 -
4803 - FREE_AND_NULL(options->parseopts);
4798 }
4799
4800 int parse_long_opt(const char *opt, const char **argv,
@@ -5399,11 +5393,6 @@ static int diff_opt_rotate_to(const struct option *opt, const char *arg, int uns
5393
5394 struct option *add_diff_options(const struct option *opts,
5395 struct diff_options *options)
5402 -{
5403 - return parse_options_concat(opts, options->parseopts);
5404 -}
5405 -
5406 -static void prep_parse_options(struct diff_options *options)
5396 {
5397 struct option parseopts[] = {
5398 OPT_GROUP(N_("Diff output format options")),
@@ -5673,8 +5662,7 @@ static void prep_parse_options(struct diff_options *options)
5662 OPT_END()
5663 };
5664
5676 - ALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts));
5677 - memcpy(options->parseopts, parseopts, sizeof(parseopts));
5665 + return parse_options_concat(opts, parseopts);
5666 }
5667
5668 int diff_opt_parse(struct diff_options *options,
@@ -6497,7 +6485,6 @@ void diff_free(struct diff_options *options)
6485 diff_free_file(options);
6486 diff_free_ignore_regex(options);
6487 clear_pathspec(&options->pathspec);
6500 - FREE_AND_NULL(options->parseopts);
6488 }
6489
6490 void diff_flush(struct diff_options *options)
diff.h
-1
@@ -394,7 +394,6 @@ struct diff_options {
394 unsigned color_moved_ws_handling;
395
396 struct repository *repo;
397 - struct option *parseopts;
397 struct strmap *additional_path_headers;
398
399 int no_free;