Skip to content

C stack overflow in error handler #24

Open
@jcelliott

Description

@jcelliott

When calling a lua function that errors, the C stack is not cleaned up. If the lua function is called many times, it will eventually overflow the stack. Any further calls to the error handler result in the error "error in error handling" being returned.

This is the smallest test case I could come up with to reproduce it. I'm on Linux using lua 5.1.5 and the most recent version of golua.

error.go:

package main

import "github.com/aarzilli/golua/lua"
import "fmt"

func main() {
    L := lua.NewState()
    L.OpenLibs()
    if err := L.DoFile("error.lua"); err != nil {
        panic(err)
    }

    // 120 worked on my machine, might be different for you
    for i:=0; i<120; i++ {
        top := L.GetTop()
        L.GetGlobal("doError")
        err := L.Call(0, lua.LUA_MULTRET)
        if err != nil {
            fmt.Println("error:", err)
            fmt.Println("stack length:", len(L.StackTrace()))
            // fmt.Println("stack:", L.StackTrace())
        }
        L.SetTop(top)
    }
}

error.lua:

function doError()
    error("something bad")
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions