Commit 77e56d5
diff.c: fix a double-free regression in a18d66c
My a18d66c (diff.c: free "buf" in diff_words_flush(), 2022-03-04)
has what it retrospect is a rather obvious bug (I don't know what I
was thinking, if it all): We use the "emitted_symbols" allocation in
append_emitted_diff_symbol() N times, but starting with a18d66c
we'd free it after its first use!
The correct way to free this data would have been to add the free() to
the existing free_diff_words_data() function, so let's do that. The
"ecbdata->diff_words->opt->emitted_symbols" might be NULL, so let's
add a trivial free_emitted_diff_symbols() helper next to the function
that appends to it.
This fixes the "no effect on show from" leak tested for in the
preceding commit. Perhaps confusingly this change will skip that test
under SANITIZE=leak, but otherwise opt-in the
"t4015-diff-whitespace.sh" test.
The reason is that a18d66c "fixed" the leak in the preceding "no
effect on diff" test, but for the first call to diff_words_flush() the
"wol->buf" would be NULL, so we wouldn't double-free (and
SANITIZE=address would see nothing amiss). With this change we'll
still pass that test, showing that we've also fixed leaks on this
codepath.
We then have to skip the new "no effect on show" test because it
happens to trip over an unrelated memory leak (in revision.c). The
same goes for "move detection with submodules". Both of them pass with
SANITIZE=address though, which would error on the "no effect on show"
test before this change.
Reported-by: Michael J Gruber <[email protected]>
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>1 parent b59ec03 commit 77e56d5
2 files changed
+13
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
803 | 811 | | |
804 | 812 | | |
805 | 813 | | |
| |||
2150 | 2158 | | |
2151 | 2159 | | |
2152 | 2160 | | |
2153 | | - | |
2154 | 2161 | | |
2155 | 2162 | | |
2156 | 2163 | | |
| |||
2228 | 2235 | | |
2229 | 2236 | | |
2230 | 2237 | | |
2231 | | - | |
| 2238 | + | |
2232 | 2239 | | |
2233 | 2240 | | |
2234 | 2241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
1636 | 1638 | | |
1637 | 1639 | | |
1638 | 1640 | | |
1639 | | - | |
| 1641 | + | |
1640 | 1642 | | |
1641 | 1643 | | |
1642 | 1644 | | |
| |||
2022 | 2024 | | |
2023 | 2025 | | |
2024 | 2026 | | |
2025 | | - | |
| 2027 | + | |
2026 | 2028 | | |
2027 | 2029 | | |
2028 | 2030 | | |
| |||
0 commit comments