You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible memory leak: runCode allocates C.CString(call.SourcePath) on every call and never frees it #53
janet_cstring copies the bytes into a Janet GC string (janet.c:30230 -> janet_string, janet.c:30191-30199), so sourcePtr is not needed after that call. It is never freed, on the normal path or on the early returns at :127-128, :153 and :168.
runCode runs for every VM.ExecuteCall (through callRequest and poll, module.go:107-109). That includes cy exec RPCs (cmd/cy/rpc.go:161-168), hook/init on every client connection (pkg/cy/client.go:139, with an empty SourcePath there), shell/attach, register/set, and config loading. In the long-running server each call leaves len(SourcePath)+1 bytes allocated.
runCodeUnsafe in the same file frees its sourcePtr (:79), and wrapFile uses defer C.free (:275-276).
Reproduction
A small program using this package (macOS arm64, Go 1.27) creates a VM with janet.New and calls ExecuteCall N times with a 48-character SourcePath (UpdateEnv: false). Under MallocStackLogging=1 leaks --atExit:
N=100: 107 leaks for 6640 total leaked bytes (100 x 64-byte blocks from _cgo_..._Cfunc__Cmalloc)
N=1000: 1007 leaks for 64240 total leaked bytes (1000 x 64-byte blocks from _cgo_..._Cfunc__Cmalloc)
The other 7 blocks are present for any N: 6 x 32 bytes from VM setup and one 48-byte xpc_date_t that macOS reports for every Go program. With the fix below, N=1000 reports only those 7 blocks, and go test ./pkg/janet/ passes.
Activity