From 16b31d9bac4dc3c41799f644b18bea433e4e9460 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Wed, 22 May 2024 13:00:26 -0300 Subject: Fix double-free with `Array` --- rust/src/disassembly.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'rust/src') diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index e3766f32..5d3da31e 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -272,28 +272,28 @@ impl Drop for InstructionTextToken { impl CoreArrayProvider for InstructionTextToken { type Raw = BNInstructionTextToken; type Context = (); - type Wrapped<'a> = Self; + type Wrapped<'a> = &'a Self; } unsafe impl CoreArrayProviderInner for InstructionTextToken { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeInstructionText(raw, count) } unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - Self(*raw) + core::mem::transmute(raw) } } impl CoreArrayProvider for Array { type Raw = BNInstructionTextLine; type Context = (); - type Wrapped<'a> = Self; + type Wrapped<'a> = mem::ManuallyDrop; } unsafe impl CoreArrayProviderInner for Array { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeInstructionTextLines(raw, count) } unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - Self::new(raw.tokens, raw.count, ()) + mem::ManuallyDrop::new(Self::new(raw.tokens, raw.count, ())) } } -- cgit v1.3.1