From f9a9abdff9cc539f5a92c56f8942946a8ac718be Mon Sep 17 00:00:00 2001 From: Xusheng Date: Mon, 11 Sep 2023 17:04:20 +0800 Subject: Fix memory leak in functions calling BNCreateUserFunction --- rust/src/binaryview.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'rust/src/binaryview.rs') 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> { 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)) } } -- cgit v1.3.1