New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Freeing quickjs.Runtime after creating a new function causes a segmentation fault. #1
Labels
bug
Something isn't working
Comments
Here is another similar case: main.go package main
import (
"github.com/lithdew/quickjs"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
rt := quickjs.NewRuntime()
for i := 0; i < 10000; i++ {
ctx := rt.NewContext()
defer ctx.Free()
globals := ctx.Globals()
globals.Set("B", ctx.Function(SetRedisObject))
ctx.Eval(`B('test',{a:'c'});`)
}
} redis.go package main
import (
"github.com/go-redis/redis"
"github.com/lithdew/quickjs"
)
var rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{"localhost:7000"},
})
func ValueToMap(v *quickjs.Value) map[string]interface{} {
if v.IsObject() == false {
panic("not an object")
}
names, err := v.PropertyNames()
check(err)
result := map[string]interface{}{}
for _, name := range names {
result[name.String()] = v.GetByAtom(name.Atom).String()
}
return result
}
func SetRedisObject(ctx quickjs.Context, this quickjs.Value, args []quickjs.Value) quickjs.Value {
err := rdb.HMSet(args[0].String(), ValueToMap(&args[1])).Err()
if err != nil {
panic(err)
}
return ctx.Null()
} produces:
|
lithdew
added a commit
that referenced
this issue
Jul 10, 2020
Fixed by ee6f6e9. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The suspicion is of possible misuse of
JS_NewCFunctionData
, which is used overJS_NewCFunction
to provide an opaque pointer toproxy()
in Go to dispatch Go functions in C.It may be that this is not the intended use of
JS_NewCFunctionData
, and that callingJS_FreeRuntime
frees unintended memory as a result.The text was updated successfully, but these errors were encountered: