Merge branch 'ab/plug-random-leaks'
Double-free fix for a recently merged topic.
* ab/plug-random-leaks:
diff.c: fix a double-free regression in a18d66cefb
tests: demonstrate "show --word-diff --color-moved" regression
maint
commit
361c2566c0
11
diff.c
11
diff.c
|
@ -800,6 +800,14 @@ static void append_emitted_diff_symbol(struct diff_options *o,
|
||||||
f->line = e->line ? xmemdupz(e->line, e->len) : NULL;
|
f->line = e->line ? xmemdupz(e->line, e->len) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void free_emitted_diff_symbols(struct emitted_diff_symbols *e)
|
||||||
|
{
|
||||||
|
if (!e)
|
||||||
|
return;
|
||||||
|
free(e->buf);
|
||||||
|
free(e);
|
||||||
|
}
|
||||||
|
|
||||||
struct moved_entry {
|
struct moved_entry {
|
||||||
const struct emitted_diff_symbol *es;
|
const struct emitted_diff_symbol *es;
|
||||||
struct moved_entry *next_line;
|
struct moved_entry *next_line;
|
||||||
|
@ -2150,7 +2158,6 @@ static void diff_words_flush(struct emit_callback *ecbdata)
|
||||||
|
|
||||||
for (i = 0; i < wol->nr; i++)
|
for (i = 0; i < wol->nr; i++)
|
||||||
free((void *)wol->buf[i].line);
|
free((void *)wol->buf[i].line);
|
||||||
free(wol->buf);
|
|
||||||
|
|
||||||
wol->nr = 0;
|
wol->nr = 0;
|
||||||
}
|
}
|
||||||
|
@ -2228,7 +2235,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
|
||||||
{
|
{
|
||||||
if (ecbdata->diff_words) {
|
if (ecbdata->diff_words) {
|
||||||
diff_words_flush(ecbdata);
|
diff_words_flush(ecbdata);
|
||||||
free (ecbdata->diff_words->opt->emitted_symbols);
|
free_emitted_diff_symbols(ecbdata->diff_words->opt->emitted_symbols);
|
||||||
free (ecbdata->diff_words->opt);
|
free (ecbdata->diff_words->opt);
|
||||||
free (ecbdata->diff_words->minus.text.ptr);
|
free (ecbdata->diff_words->minus.text.ptr);
|
||||||
free (ecbdata->diff_words->minus.orig);
|
free (ecbdata->diff_words->minus.orig);
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
test_description='Test special whitespace in diff engine.
|
test_description='Test special whitespace in diff engine.
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
TEST_PASSES_SANITIZE_LEAK=true
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY"/lib-diff.sh
|
. "$TEST_DIRECTORY"/lib-diff.sh
|
||||||
|
|
||||||
|
@ -1622,7 +1624,7 @@ test_expect_success 'cmd option assumes configured colored-moved' '
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'no effect from --color-moved with --word-diff' '
|
test_expect_success 'no effect on diff from --color-moved with --word-diff' '
|
||||||
cat <<-\EOF >text.txt &&
|
cat <<-\EOF >text.txt &&
|
||||||
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
|
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
|
||||||
EOF
|
EOF
|
||||||
|
@ -1636,6 +1638,12 @@ test_expect_success 'no effect from --color-moved with --word-diff' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success !SANITIZE_LEAK 'no effect on show from --color-moved with --word-diff' '
|
||||||
|
git show --color-moved --word-diff >actual &&
|
||||||
|
git show --word-diff >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'set up whitespace tests' '
|
test_expect_success 'set up whitespace tests' '
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
# Note that these lines have no leading or trailing whitespace.
|
# Note that these lines have no leading or trailing whitespace.
|
||||||
|
@ -2016,7 +2024,7 @@ test_expect_success '--color-moved rewinds for MIN_ALNUM_COUNT' '
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'move detection with submodules' '
|
test_expect_success !SANITIZE_LEAK 'move detection with submodules' '
|
||||||
test_create_repo bananas &&
|
test_create_repo bananas &&
|
||||||
echo ripe >bananas/recipe &&
|
echo ripe >bananas/recipe &&
|
||||||
git -C bananas add recipe &&
|
git -C bananas add recipe &&
|
||||||
|
|
Loading…
Reference in New Issue