diff options
| author | Mason Reed <mason@vector35.com> | 2024-10-26 20:33:45 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2024-10-26 20:33:45 -0400 |
| commit | 952d16ca58429d126224662f4f5f496a0535c7ac (patch) | |
| tree | 82583dcbf8349d2678f7a8762346a493571070ae /rust/src | |
| parent | 4864ede6684833163153343b9604619c7e7a5dd6 (diff) | |
Fix all low level il function getters leaking in rust
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/function.rs | 8 | ||||
| -rw-r--r-- | rust/src/llil/function.rs | 13 | ||||
| -rw-r--r-- | rust/src/workflow.rs | 4 |
3 files changed, 14 insertions, 11 deletions
diff --git a/rust/src/function.rs b/rust/src/function.rs index 0508ca4d..0df9fcf5 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -427,7 +427,7 @@ impl Function { return Err(()); } - Ok(llil::RegularFunction::from_raw(self.arch(), llil)) + Ok(llil::RegularFunction::ref_from_raw(self.arch(), llil)) } } @@ -435,7 +435,7 @@ impl Function { &self, ) -> Option<Ref<llil::RegularFunction<CoreArchitecture>>> { let llil = unsafe { BNGetFunctionLowLevelILIfAvailable(self.handle) }; - (!llil.is_null()).then(|| unsafe { llil::RegularFunction::from_raw(self.arch(), llil) }) + (!llil.is_null()).then(|| unsafe { llil::RegularFunction::ref_from_raw(self.arch(), llil) }) } pub fn lifted_il(&self) -> Result<Ref<llil::LiftedFunction<CoreArchitecture>>, ()> { @@ -446,13 +446,13 @@ impl Function { return Err(()); } - Ok(llil::LiftedFunction::from_raw(self.arch(), llil)) + Ok(llil::LiftedFunction::ref_from_raw(self.arch(), llil)) } } pub fn lifted_il_if_available(&self) -> Option<Ref<llil::LiftedFunction<CoreArchitecture>>> { let llil = unsafe { BNGetFunctionLiftedILIfAvailable(self.handle) }; - (!llil.is_null()).then(|| unsafe { llil::LiftedFunction::from_raw(self.arch(), llil) }) + (!llil.is_null()).then(|| unsafe { llil::LiftedFunction::ref_from_raw(self.arch(), llil) }) } pub fn return_type(&self) -> Conf<Ref<Type>> { diff --git a/rust/src/llil/function.rs b/rust/src/llil/function.rs index 8f1eac62..abc501e5 100644 --- a/rust/src/llil/function.rs +++ b/rust/src/llil/function.rs @@ -84,10 +84,7 @@ where M: FunctionMutability, F: FunctionForm, { - pub(crate) unsafe fn from_raw( - borrower: A::Handle, - handle: *mut BNLowLevelILFunction, - ) -> Ref<Self> { + pub(crate) unsafe fn from_raw(borrower: A::Handle, handle: *mut BNLowLevelILFunction) -> Self { debug_assert!(!handle.is_null()); Self { @@ -97,7 +94,13 @@ where _mutability: PhantomData, _form: PhantomData, } - .to_owned() + } + + pub(crate) unsafe fn ref_from_raw( + borrower: A::Handle, + handle: *mut BNLowLevelILFunction, + ) -> Ref<Self> { + Ref::new(Self::from_raw(borrower, handle)) } pub(crate) fn arch(&self) -> &A { diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs index 8409ad70..246571a8 100644 --- a/rust/src/workflow.rs +++ b/rust/src/workflow.rs @@ -52,7 +52,7 @@ impl AnalysisContext { let result = unsafe { BNGetFunctionLiftedIL(func.handle) }; let arch = self.function().arch(); unsafe { - Some(llil::Function::from_raw( + Some(llil::Function::ref_from_raw( arch, NonNull::new(result)?.as_ptr(), )) @@ -73,7 +73,7 @@ impl AnalysisContext { let result = unsafe { BNAnalysisContextGetLowLevelILFunction(self.handle.as_ptr()) }; let arch = self.function().arch(); unsafe { - Some(llil::Function::from_raw( + Some(llil::Function::ref_from_raw( arch, NonNull::new(result)?.as_ptr(), )) |
