Skip to content

Commit 3c0adf5

Browse files
committed
[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.
1 parent ee11cbb commit 3c0adf5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

rust/src/high_level_il/function.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ impl HighLevelILFunction {
6969
unsafe { BNGetHighLevelILExprCount(self.handle) }
7070
}
7171

72-
pub fn ssa_form(&self) -> HighLevelILFunction {
72+
pub fn ssa_form(&self) -> Ref<HighLevelILFunction> {
7373
let ssa = unsafe { BNGetHighLevelILSSAForm(self.handle) };
7474
assert!(!ssa.is_null());
75-
HighLevelILFunction {
76-
handle: ssa,
77-
full_ast: self.full_ast,
78-
}
75+
unsafe { HighLevelILFunction::ref_from_raw(ssa, self.full_ast) }
7976
}
8077

8178
pub fn function(&self) -> Ref<Function> {

rust/src/medium_level_il/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ impl MediumLevelILFunction {
9191
unsafe { BNGetMediumLevelILExprCount(self.handle) }
9292
}
9393

94-
pub fn ssa_form(&self) -> MediumLevelILFunction {
94+
pub fn ssa_form(&self) -> Ref<MediumLevelILFunction> {
9595
let ssa = unsafe { BNGetMediumLevelILSSAForm(self.handle) };
9696
assert!(!ssa.is_null());
97-
MediumLevelILFunction { handle: ssa }
97+
unsafe { MediumLevelILFunction::ref_from_raw(ssa) }
9898
}
9999

100100
pub fn function(&self) -> Ref<Function> {

0 commit comments

Comments
 (0)