From ec88a5c09a47e1f0859e80cada20ea1cae00ec6b Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sat, 6 Jul 2024 16:20:26 +0200 Subject: [PATCH] fix(multilinear-extensions): address concerns of double free on copy --- constantine/boolean_hypercube/multilinear_extensions.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/constantine/boolean_hypercube/multilinear_extensions.nim b/constantine/boolean_hypercube/multilinear_extensions.nim index efcd1931..147001db 100644 --- a/constantine/boolean_hypercube/multilinear_extensions.nim +++ b/constantine/boolean_hypercube/multilinear_extensions.nim @@ -40,6 +40,11 @@ type num_vars*: int base_poly_evals*: ptr UncheckedArray[F] +proc `=copy`*[F](dst: var MultilinearExtension[F], src: MultilinearExtension[F]) {.error: "A multilinear extension cannot be copied".} + +proc `=wasMoved`*[F](mle: var MultilinearExtension[F]) = + mle.base_poly_evals = nil + proc `=destroy`*[F](mle: var MultilinearExtension[F]) = if not mle.base_poly_evals.isNil: freeHeapAligned(mle.base_poly_evals)