From 9dea0e3a04dab39d407407aaa3da14ed72f3bd22 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 3 Feb 2022 22:17:50 -0500 Subject: [PATCH] Automatically deallocate Failures in Rust --- compiler/gen_llvm/src/run_roc.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/compiler/gen_llvm/src/run_roc.rs b/compiler/gen_llvm/src/run_roc.rs index 8835b00b37..812fbdede6 100644 --- a/compiler/gen_llvm/src/run_roc.rs +++ b/compiler/gen_llvm/src/run_roc.rs @@ -68,6 +68,22 @@ macro_rules! run_jit_function { count: usize, } + impl Drop for Failures { + fn drop(&mut self) { + use std::alloc::{dealloc, Layout}; + use std::mem; + + unsafe { + let layout = Layout::from_size_align_unchecked( + mem::size_of::(), + mem::align_of::(), + ); + + dealloc(self.failures as *mut u8, layout); + } + } + } + let get_expect_failures: libloading::Symbol Failures> = $lib .get(bitcode::UTILS_GET_EXPECT_FAILURES.as_bytes()) .ok()