fix(eval): prevent double-free in garbage collection (#22990)

This commit is contained in:
zeertzjq 2023-04-10 18:06:59 +08:00 committed by GitHub
parent 5ed7ede1f5
commit 0e4086b741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -1149,7 +1149,7 @@ void vars_clear_ext(hashtab_T *ht, int free_val)
}
}
hash_clear(ht);
ht->ht_used = 0;
hash_init(ht);
}
/// Delete a variable from hashtab "ht" at item "hi".

View File

@ -220,3 +220,38 @@ describe('listing functions using :function', function()
assert_alive()
end)
end)
it('no double-free in garbage collection #16287', function()
clear()
-- Don't use exec() here as using a named script reproduces the issue better.
write_file('Xgarbagecollect.vim', [[
func Foo() abort
let s:args = [a:000]
let foo0 = ""
let foo1 = ""
let foo2 = ""
let foo3 = ""
let foo4 = ""
let foo5 = ""
let foo6 = ""
let foo7 = ""
let foo8 = ""
let foo9 = ""
let foo10 = ""
let foo11 = ""
let foo12 = ""
let foo13 = ""
let foo14 = ""
endfunc
set updatetime=1
call Foo()
call Foo()
]])
finally(function()
os.remove('Xgarbagecollect.vim')
end)
command('source Xgarbagecollect.vim')
sleep(10)
assert_alive()
end)