avoid dangling cstring in handleRes under ARC/ORC

This commit is contained in:
Ivan FB 2026-04-24 13:13:57 +02:00
parent 3ecea05bb6
commit 66ef92ad26
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270

View File

@ -55,9 +55,11 @@ proc handleRes*[T: string | void](
return
foreignThreadGc:
var msg: cstring = ""
var resStr: string
## we need to bind the string to extend its lifetime to callback's in ARC/ORC
when T is string:
msg = res.get().cstring()
resStr = res.get()
let msg: cstring = resStr.cstring()
request[].callback(
RET_OK, unsafeAddr msg[0], cast[csize_t](len(msg)), request[].userData
)
@ -65,4 +67,3 @@ proc handleRes*[T: string | void](
proc nilProcess*(reqId: cstring): Future[Result[string, string]] {.async.} =
return err("This request type is not implemented: " & $reqId)