From ee5063327e3ddefaa59ee2ff90e6e9f54eca2076 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 2 Feb 2025 19:34:27 -0500 Subject: Fix leaking BNDataVariableAndName when calling BNGetDebugDataVariableBy functions --- rust/src/debuginfo.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'rust/src/debuginfo.rs') diff --git a/rust/src/debuginfo.rs b/rust/src/debuginfo.rs index 72d5fdab..11d5f249 100644 --- a/rust/src/debuginfo.rs +++ b/rust/src/debuginfo.rs @@ -562,18 +562,18 @@ impl DebugInfo { ) -> Option { let parser_name = parser_name.into_bytes_with_nul(); let name = name.into_bytes_with_nul(); - let raw_named_var = unsafe { - BNGetDebugDataVariableByName( + let mut dv = BNDataVariableAndName::default(); + unsafe { + if BNGetDebugDataVariableByName( self.handle, parser_name.as_ref().as_ptr() as *mut _, name.as_ref().as_ptr() as *mut _, - ) - }; - - if !raw_named_var.is_null() { - Some(unsafe { NamedDataVariableWithType::from_ref_raw(raw_named_var) }) - } else { - None + &mut dv, + ) { + Some(NamedDataVariableWithType::from_owned_raw(dv)) + } else { + None + } } } @@ -583,18 +583,18 @@ impl DebugInfo { address: u64, ) -> Option { let parser_name = parser_name.into_bytes_with_nul(); - let raw_named_var = unsafe { - BNGetDebugDataVariableByAddress( + let mut dv = BNDataVariableAndName::default(); + unsafe { + if BNGetDebugDataVariableByAddress( self.handle, parser_name.as_ref().as_ptr() as *mut _, address, - ) - }; - - if !raw_named_var.is_null() { - Some(unsafe { NamedDataVariableWithType::from_ref_raw(raw_named_var) }) - } else { - None + &mut dv, + ) { + Some(NamedDataVariableWithType::from_owned_raw(dv)) + } else { + None + } } } -- cgit v1.3.1