Skip to content

Commit b709dd9

Browse files
committed
[Rust] Fix leaking the context of a data notification handle on drop
1 parent 82cee46 commit b709dd9

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

rust/src/data_notification.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,9 @@ impl<T: CustomDataNotification> DataNotificationHandle<'_, T> {
472472
Box::from_raw(self.handle.context as *mut T)
473473
}
474474

475-
pub fn unregister(self) -> T {
476-
// NOTE: Don't drop the ctxt, return it
477-
let mut slf = core::mem::ManuallyDrop::new(self);
478-
unsafe { slf.unregister_bv() };
479-
unsafe { *slf.extract_context() }
475+
pub fn unregister(mut self) -> T {
476+
unsafe { self.unregister_bv() };
477+
unsafe { *self.extract_context() }
480478
}
481479
}
482480

@@ -500,19 +498,17 @@ where
500498
}
501499

502500
impl<T: CustomDataNotification> PersistedDataNotificationHandle<'_, T> {
503-
unsafe fn unregister_bv(&mut self, view: &BinaryView) {
501+
unsafe fn unregister_for_view(&mut self, view: &BinaryView) {
504502
BNUnregisterDataNotification(view.handle, self.handle.as_mut())
505503
}
506504

507505
unsafe fn extract_context(&mut self) -> Box<T> {
508506
Box::from_raw(self.handle.context as *mut T)
509507
}
510508

511-
pub fn unregister(self, view: &BinaryView) -> T {
512-
// NOTE: Don't drop the ctxt, return it
513-
let mut slf = core::mem::ManuallyDrop::new(self);
514-
unsafe { slf.unregister_bv(view) };
515-
unsafe { *slf.extract_context() }
509+
pub fn unregister(mut self, view: &BinaryView) -> T {
510+
unsafe { self.unregister_for_view(view) };
511+
unsafe { *self.extract_context() }
516512
}
517513
}
518514

0 commit comments

Comments
 (0)