diff options
| author | Xusheng <xusheng@vector35.com> | 2023-09-11 17:04:20 +0800 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2023-09-11 13:24:31 -0400 |
| commit | f9a9abdff9cc539f5a92c56f8942946a8ac718be (patch) | |
| tree | 05fce5a4a252c2768d448e5b8b61cb101ad7d125 /rust | |
| parent | b4da85f227630f8a1d7f4328f45e0f7d3d5a7e29 (diff) | |
Fix memory leak in functions calling BNCreateUserFunction
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/binaryview.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 31a12105..d6916e2c 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -853,9 +853,15 @@ pub trait BinaryViewExt: BinaryViewBase { } } - fn create_user_function(&self, plat: &Platform, addr: u64) { + fn create_user_function(&self, plat: &Platform, addr: u64) -> Result<Ref<Function>> { unsafe { - BNCreateUserFunction(self.as_ref().handle, plat.handle, addr); + let func = BNCreateUserFunction(self.as_ref().handle, plat.handle, addr); + + if func.is_null() { + return Err(()); + } + + Ok(Function::from_raw(func)) } } |
