summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-02-02 19:34:27 -0500
committerMason Reed <mason@vector35.com>2025-02-13 13:00:05 -0500
commitee5063327e3ddefaa59ee2ff90e6e9f54eca2076 (patch)
tree15fd185a398de6a08832839cd78f1fbe5393b86a /rust
parent1014cb1872c06b7dbfbee55d4a0b4e6a5743ec6b (diff)
Fix leaking BNDataVariableAndName when calling BNGetDebugDataVariableBy functions
Diffstat (limited to 'rust')
-rw-r--r--rust/src/debuginfo.rs36
-rw-r--r--rust/src/variable.rs10
2 files changed, 18 insertions, 28 deletions
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<NamedDataVariableWithType> {
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<NamedDataVariableWithType> {
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
+ }
}
}
diff --git a/rust/src/variable.rs b/rust/src/variable.rs
index 260e12d8..3fdc1177 100644
--- a/rust/src/variable.rs
+++ b/rust/src/variable.rs
@@ -119,12 +119,6 @@ impl NamedDataVariableWithType {
owned
}
- pub(crate) unsafe fn from_ref_raw(value: *mut BNDataVariableAndName) -> Self {
- let owned = Self::from_raw(&*value);
- Self::free_ref_raw(value);
- owned
- }
-
pub(crate) fn into_raw(value: Self) -> BNDataVariableAndName {
let bn_name = BnString::new(value.name);
BNDataVariableAndName {
@@ -136,10 +130,6 @@ impl NamedDataVariableWithType {
}
}
- pub(crate) fn free_ref_raw(value: *mut BNDataVariableAndName) {
- unsafe { BNFreeDataVariableAndName(value) }
- }
-
pub(crate) fn free_raw(value: BNDataVariableAndName) {
let _ = unsafe { Type::ref_from_raw(value.type_) };
let _ = unsafe { BnString::from_raw(value.name) };