umka-lang
umka-lang copied to clipboard
Memory leak if a fiber function does not return
The reference count for buf is increased when passed to fiberspawn() and decreased upon returning from f(). If fibercall() is not called, it never gets decreased.
fn f(parent: ^fiber, buf: ^int) {}
fn main() {
buf := new(int)
thread := fiberspawn(f, buf)
}
This code also causes the problem:
fn f(parent: ^fiber, buf: ^int) {
printf("In thread\n")
fibercall(parent)
}
fn main() {
buf := new(int)
thread := fiberspawn(f, buf)
fibercall(thread)
}
fn foo(parent: fiber, ctx: ^int) {
a := make([]int, 10000) // Runtime error: No memory
fibercall(parent)
}
fn main() {
for i := 0; i < 10000; i++ {
ctx := new(int)
fibercall(fiberspawn(foo, ctx))
}
}