[PATCH v2 0/3] diff: build parseopts array on demand
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 1, 2022, 13:39 UTC
- Message-ID
- <ea838ae7-b635-d4d2-d9df-e96b3d8980af@web.de>
- In-Reply-To
- <0620b4a6-b80a-d8a0-5a35-857b9fe0c986@web.de>
Calling repo_init_revisions() and release_revisions() in that order leaks the memory allocated for the parseopts array in the embedded struct diff_options member. Get rid of that leak by reducing the lifetime of that array.
Original patch: https://lore.kernel.org/git/4fd82dc6-e0f8-0638-5b10-16bfef39a171@web.de/
Submitted separately from that thread because it's independent enough.
Change since v1: - Actually remove the parseopts member. Its removal got lost during refactoring in v1. Thank you for spotting that, Junio!
diff: factor out add_diff_options() diff: let prep_parse_options() return parseopt array diff: remove parseopts member from struct diff_options
builtin/range-diff.c | 2 +- diff-no-index.c | 3 +-- diff.c | 26 +++++++++++++++----------- diff.h | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-)
Range-Diff gegen v1:
1: 630f95320f = 1: 4dc8b2632b diff: factor out add_diff_options()
2: 4b56fa795c = 2: 10903d355e diff: let prep_parse_options() return parseopt array
3: 7e54e4370a ! 3: 24bd18ae79 diff: remove parseopts member from struct diff_options
@@ diff.c: void diff_free(struct diff_options *options)
} void diff_flush(struct diff_options *options)
+
+ ## diff.h ##
+@@ diff.h: struct diff_options {
+ unsigned color_moved_ws_handling;
+
+ struct repository *repo;
+- struct option *parseopts;
+ struct strmap *additional_path_headers;
+
+ int no_free;
--
2.38.1