mirror of https://github.com/waku-org/nwaku.git
waku_thread_response.nim: use correct alloc() proc to allocate response correctly (#2277)
This commit is contained in:
parent
28142f40b6
commit
45b0be8e75
|
@ -6,6 +6,8 @@
|
||||||
import
|
import
|
||||||
std/json,
|
std/json,
|
||||||
stew/results
|
stew/results
|
||||||
|
import
|
||||||
|
../../alloc
|
||||||
|
|
||||||
type
|
type
|
||||||
ResponseType {.pure.} = enum
|
ResponseType {.pure.} = enum
|
||||||
|
@ -26,13 +28,11 @@ proc createShared*(T: type InterThreadResponse,
|
||||||
if res.isOk():
|
if res.isOk():
|
||||||
let value = res.get()
|
let value = res.get()
|
||||||
ret[].respType = ResponseType.OK
|
ret[].respType = ResponseType.OK
|
||||||
ret[].content = cast[cstring](allocShared0(value.len + 1))
|
ret[].content = value.alloc()
|
||||||
copyMem(ret[].content, unsafeAddr value, value.len + 1)
|
|
||||||
else:
|
else:
|
||||||
let error = res.error
|
let error = res.error
|
||||||
ret[].respType = ResponseType.ERR
|
ret[].respType = ResponseType.ERR
|
||||||
ret[].content = cast[cstring](allocShared0(error.len + 1))
|
ret[].content = res.error.alloc()
|
||||||
copyMem(ret[].content, unsafeAddr error, error.len + 1)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
proc process*(T: type InterThreadResponse,
|
proc process*(T: type InterThreadResponse,
|
||||||
|
|
Loading…
Reference in New Issue