From 3c0adf5d445a1f691905af589abea7818a9517da Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Sat, 3 May 2025 22:39:50 -0700 Subject: [PATCH 1/2] [Rust] Avoid leaking a reference within {Medium,High}LevelILFunction::ssa_form Return a Ref<_> so that the underlying core object will have its reference count decremented when the caller drops the object. --- rust/src/high_level_il/function.rs | 7 ++----- rust/src/medium_level_il/function.rs | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/rust/src/high_level_il/function.rs b/rust/src/high_level_il/function.rs index aad16e14bc..0813ad0458 100644 --- a/rust/src/high_level_il/function.rs +++ b/rust/src/high_level_il/function.rs @@ -69,13 +69,10 @@ impl HighLevelILFunction { unsafe { BNGetHighLevelILExprCount(self.handle) } } - pub fn ssa_form(&self) -> HighLevelILFunction { + pub fn ssa_form(&self) -> Ref { let ssa = unsafe { BNGetHighLevelILSSAForm(self.handle) }; assert!(!ssa.is_null()); - HighLevelILFunction { - handle: ssa, - full_ast: self.full_ast, - } + unsafe { HighLevelILFunction::ref_from_raw(ssa, self.full_ast) } } pub fn function(&self) -> Ref { diff --git a/rust/src/medium_level_il/function.rs b/rust/src/medium_level_il/function.rs index 5cc0b58b52..0ac82ff182 100644 --- a/rust/src/medium_level_il/function.rs +++ b/rust/src/medium_level_il/function.rs @@ -91,10 +91,10 @@ impl MediumLevelILFunction { unsafe { BNGetMediumLevelILExprCount(self.handle) } } - pub fn ssa_form(&self) -> MediumLevelILFunction { + pub fn ssa_form(&self) -> Ref { let ssa = unsafe { BNGetMediumLevelILSSAForm(self.handle) }; assert!(!ssa.is_null()); - MediumLevelILFunction { handle: ssa } + unsafe { MediumLevelILFunction::ref_from_raw(ssa) } } pub fn function(&self) -> Ref { From c2ad7ea7b666faa8f244b2c4a8e31f85bc0cf035 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Sat, 3 May 2025 23:19:08 -0700 Subject: [PATCH 2/2] [Rust] Fix a pre-existing formatting issue CI is complaining about it. --- rust/src/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs index bdb9a88f76..fc935cd506 100644 --- a/rust/src/metadata.rs +++ b/rust/src/metadata.rs @@ -239,7 +239,7 @@ impl Metadata { }; map.insert(key, value); } - + unsafe { BNFreeMetadataValueStore(ptr) }; Ok(map)