Skip to content

Commit d44e526

Browse files
rscharfegitster
authored andcommitted
diff-lib: plug minor memory leaks in do_diff_cache()
do_diff_cache() builds a struct rev_info to hand to diff_cache() from scratch by initializing it using repo_init_revisions() and then replacing its diffopt and prune_data members. The diffopt member is initialized to a heap-allocated list of options, though. Release it using diff_setup_done() before overwriting it. The initial value of the prune_data member doesn't need to be released, but the copy created using copy_pathspec() does. Clear it after use. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 898f807 commit d44e526

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

diff-lib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,12 @@ int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt)
536536

537537
repo_init_revisions(opt->repo, &revs, NULL);
538538
copy_pathspec(&revs.prune_data, &opt->pathspec);
539+
diff_setup_done(&revs.diffopt);
539540
revs.diffopt = *opt;
540541

541542
if (diff_cache(&revs, tree_oid, NULL, 1))
542543
exit(128);
544+
clear_pathspec(&revs.prune_data);
543545
return 0;
544546
}
545547

0 commit comments

Comments
 (0)