umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

Memory leak if a fiber function does not return

Open vtereshkov opened this issue 5 years ago • 1 comments

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)
}

vtereshkov avatar Aug 21 '20 12:08 vtereshkov

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)
}

vtereshkov avatar Dec 28 '21 23:12 vtereshkov

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))
        }
}

vtereshkov avatar Dec 17 '22 11:12 vtereshkov