[nim] Prevent free_trusted_setup double call issue (#426)
This commit is contained in:
parent
c9e4634307
commit
98c419eed5
|
@ -13,6 +13,7 @@ export
|
||||||
|
|
||||||
type
|
type
|
||||||
KzgCtx* = ref object
|
KzgCtx* = ref object
|
||||||
|
valFreed: bool
|
||||||
val: KzgSettings
|
val: KzgSettings
|
||||||
|
|
||||||
KzgProofAndY* = object
|
KzgProofAndY* = object
|
||||||
|
@ -32,7 +33,12 @@ else:
|
||||||
##############################################################
|
##############################################################
|
||||||
|
|
||||||
proc destroy*(x: KzgCtx) =
|
proc destroy*(x: KzgCtx) =
|
||||||
free_trusted_setup(x.val)
|
# Prevent Nim GC to call free_trusted_setup
|
||||||
|
# if user already done it before.
|
||||||
|
# Otherwise, the program will crash with segfault.
|
||||||
|
if not x.valFreed:
|
||||||
|
free_trusted_setup(x.val)
|
||||||
|
x.valFreed = true
|
||||||
|
|
||||||
proc newKzgCtx(): KzgCtx =
|
proc newKzgCtx(): KzgCtx =
|
||||||
# Nim finalizer is still broken(v1.6)
|
# Nim finalizer is still broken(v1.6)
|
||||||
|
@ -209,8 +215,8 @@ template loadTrustedSetupFile*(input: File | string): untyped =
|
||||||
loadTrustedSetup(input)
|
loadTrustedSetup(input)
|
||||||
|
|
||||||
template freeTrustedSetup*(ctx: KzgCtx) =
|
template freeTrustedSetup*(ctx: KzgCtx) =
|
||||||
free_trusted_setup(ctx.val)
|
destroy(ctx)
|
||||||
|
|
||||||
template blobToKzgCommitment*(ctx: KzgCtx,
|
template blobToKzgCommitment*(ctx: KzgCtx,
|
||||||
blob: KzgBlob): untyped =
|
blob: KzgBlob): untyped =
|
||||||
toCommitment(ctx, blob)
|
toCommitment(ctx, blob)
|
||||||
|
|
Loading…
Reference in New Issue