mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-05-06 10:19:33 +00:00
avoid dangling cstring in handleRes under ARC/ORC
This commit is contained in:
parent
3ecea05bb6
commit
66ef92ad26
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user