Skip to content

Commit 189e97b

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c6048f commit 189e97b

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

diff.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,8 +4593,6 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
45934593
builtin_checkdiff(name, other, attr_path, p->one, p->two, o);
45944594
}
45954595

4596-
static void prep_parse_options(struct diff_options *options);
4597-
45984596
void repo_diff_setup(struct repository *r, struct diff_options *options)
45994597
{
46004598
memcpy(options, &default_diff_options, sizeof(*options));
@@ -4640,8 +4638,6 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
46404638

46414639
options->color_moved = diff_color_moved_default;
46424640
options->color_moved_ws_handling = diff_color_moved_ws_default;
4643-
4644-
prep_parse_options(options);
46454641
}
46464642

46474643
static const char diff_status_letters[] = {
@@ -4799,8 +4795,6 @@ void diff_setup_done(struct diff_options *options)
47994795
options->filter = ~filter_bit[DIFF_STATUS_FILTER_AON];
48004796
options->filter &= ~options->filter_not;
48014797
}
4802-
4803-
FREE_AND_NULL(options->parseopts);
48044798
}
48054799

48064800
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
53995393

54005394
struct option *add_diff_options(const struct option *opts,
54015395
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)
54075396
{
54085397
struct option parseopts[] = {
54095398
OPT_GROUP(N_("Diff output format options")),
@@ -5673,8 +5662,7 @@ static void prep_parse_options(struct diff_options *options)
56735662
OPT_END()
56745663
};
56755664

5676-
ALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts));
5677-
memcpy(options->parseopts, parseopts, sizeof(parseopts));
5665+
return parse_options_concat(opts, parseopts);
56785666
}
56795667

56805668
int diff_opt_parse(struct diff_options *options,
@@ -6497,7 +6485,6 @@ void diff_free(struct diff_options *options)
64976485
diff_free_file(options);
64986486
diff_free_ignore_regex(options);
64996487
clear_pathspec(&options->pathspec);
6500-
FREE_AND_NULL(options->parseopts);
65016488
}
65026489

65036490
void diff_flush(struct diff_options *options)

diff.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ struct diff_options {
394394
unsigned color_moved_ws_handling;
395395

396396
struct repository *repo;
397-
struct option *parseopts;
398397
struct strmap *additional_path_headers;
399398

400399
int no_free;

0 commit comments

Comments
 (0)