builtin: fix a leak in string.index_kmp

pull/9447/head
Delyan Angelov 2021-03-23 21:48:08 +02:00
parent b335d47b72
commit 026f8424c2
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 4 additions and 0 deletions

View File

@ -712,11 +712,15 @@ pub fn (s string) index(p string) ?int {
}
// index_kmp does KMP search.
[manualfree]
fn (s string) index_kmp(p string) int {
if p.len > s.len {
return -1
}
mut prefix := []int{len: p.len}
defer {
unsafe { prefix.free() }
}
mut j := 0
for i := 1; i < p.len; i++ {
for unsafe { p.str[j] != p.str[i] } && j > 0 {