builtin: fix a leak in string.index_kmp
parent
b335d47b72
commit
026f8424c2
|
@ -712,11 +712,15 @@ pub fn (s string) index(p string) ?int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// index_kmp does KMP search.
|
// index_kmp does KMP search.
|
||||||
|
[manualfree]
|
||||||
fn (s string) index_kmp(p string) int {
|
fn (s string) index_kmp(p string) int {
|
||||||
if p.len > s.len {
|
if p.len > s.len {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
mut prefix := []int{len: p.len}
|
mut prefix := []int{len: p.len}
|
||||||
|
defer {
|
||||||
|
unsafe { prefix.free() }
|
||||||
|
}
|
||||||
mut j := 0
|
mut j := 0
|
||||||
for i := 1; i < p.len; i++ {
|
for i := 1; i < p.len; i++ {
|
||||||
for unsafe { p.str[j] != p.str[i] } && j > 0 {
|
for unsafe { p.str[j] != p.str[i] } && j > 0 {
|
||||||
|
|
Loading…
Reference in New Issue