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
var gSystemRng {.threadvar.}: SystemRng## System thread global RNG
but this seems like marking the variable as {.threadvar.} is avoidable entirely. After examining the way gSystemRng is initialized (when being compiled on Linux),
let res =syscall(SYS_getrandom, addr data, 1, GRND_NONBLOCK)
if res ==-1:
let err =osLastError().int32
if err ==ENOSYSor err ==EPERM:
result.getRandomPresent =false
procgetSystemRNG(): SystemRng=
if gSystemRng.isNil: gSystemRng =newSystemRng()
result= gSystemRng
it seems that we could have
var gSystemRng: SystemRng=newSystemRNG() ## System thread global RNG
which does not have {.threadvar.}. Are there any issues I am overlooking with this approach?
I agree that this isn't a genuine leak since it is a global variable and the memory always still has a reference, but having Valgrind not complain would be a nice feature to have.
The text was updated successfully, but these errors were encountered:
n5m
changed the title
sysrand leaks threadlocal variables
sysrand leaks threadvar variables
Nov 1, 2020
At this point, since Nimcrypto requires Nim 1.6 regardless, and https://nim-lang.org/docs/sysrand.html is available (different implementation, same name, same concept/intention) in the Nim standard library, is that an appropriate replacement for Nimcrypto's own sysrand?
Calling
sysrand.randomBytes
causes Valgrind to mark memory as "possibly lost."Example
Compile
Run
This "leak" happens because the global RNG is marked as
{.threadvar.}
:nimcrypto/nimcrypto/sysrand.nim
Line 110 in a065c17
but this seems like marking the variable as
{.threadvar.}
is avoidable entirely. After examining the waygSystemRng
is initialized (when being compiled on Linux),nimcrypto/nimcrypto/sysrand.nim
Lines 112 to 127 in a065c17
it seems that we could have
which does not have
{.threadvar.}
. Are there any issues I am overlooking with this approach?I agree that this isn't a genuine leak since it is a global variable and the memory always still has a reference, but having Valgrind not complain would be a nice feature to have.
The text was updated successfully, but these errors were encountered: