summaryrefslogtreecommitdiff
path: root/rust/src/custombinaryview.rs
diff options
context:
space:
mode:
authorRubens Brandao <git@rubens.io>2024-04-17 09:35:12 -0300
committerRubens Brandao <git@rubens.io>2024-04-17 09:41:58 -0300
commit9717866665a42356881b062fcd80bc09492ee8b8 (patch)
tree3deda26aa66d55689eaf1333b67fceed0631b27a /rust/src/custombinaryview.rs
parentf408eb32085956f7e29e0f15fd92aa4b72453370 (diff)
remove unecessary and crash causing zeroed call inits
Diffstat (limited to 'rust/src/custombinaryview.rs')
-rw-r--r--rust/src/custombinaryview.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs
index 956be9bd..14fefdf7 100644
--- a/rust/src/custombinaryview.rs
+++ b/rust/src/custombinaryview.rs
@@ -20,6 +20,7 @@ pub use binaryninjacore_sys::BNModificationStatus as ModificationStatus;
use std::marker::PhantomData;
use std::mem;
+use std::mem::MaybeUninit;
use std::os::raw::c_void;
use std::ptr;
use std::slice;
@@ -122,11 +123,10 @@ where
let long_name = long_name.into_bytes_with_nul();
let long_name_ptr = long_name.as_ref().as_ptr() as *mut _;
- let ctxt = Box::new(unsafe { mem::zeroed() });
- let ctxt = Box::into_raw(ctxt);
+ let ctxt = Box::leak(Box::new(MaybeUninit::zeroed()));
let mut bn_obj = BNCustomBinaryViewType {
- context: ctxt as *mut _,
+ context: ctxt.as_mut_ptr() as *mut _,
create: Some(cb_create::<T>),
parse: Some(cb_parse::<T>),
isValidForData: Some(cb_valid::<T>),
@@ -140,15 +140,16 @@ where
if res.is_null() {
// avoid leaking the space allocated for the type, but also
// avoid running its Drop impl (if any -- not that there should
- // be one since view types live for the life of the process)
- mem::forget(*Box::from_raw(ctxt));
+ // be one since view types live for the life of the process) as
+ // MaybeUninit suppress the Drop implementation of it's inner type
+ drop(Box::from_raw(ctxt));
panic!("bvt registration failed");
}
- ptr::write(ctxt, constructor(BinaryViewType(res)));
+ ctxt.write(constructor(BinaryViewType(res)));
- &*ctxt
+ ctxt.assume_init_mut()
}
}