binder: rust: Fix dropped service memleak
When `Binder<T>` objects die, they call the on_destroy for their class.
On creation, the value was put into a Box. On destruction,
`ptr::drop_in_place` was used to drop them. This means that while `Drop`
was called on T, the box was not freed.
Bug: 190517824
Test: Ran with showmap to confirm operations not leaking
Merged-In: Ie9932cc67016eecff4d24ac0c8fcd1bc7df27b32
Change-Id: Ie9932cc67016eecff4d24ac0c8fcd1bc7df27b32
diff --git a/libs/binder/rust/src/native.rs b/libs/binder/rust/src/native.rs
index 3b3fd08..3920129 100644
--- a/libs/binder/rust/src/native.rs
+++ b/libs/binder/rust/src/native.rs
@@ -24,7 +24,6 @@
use std::ffi::{c_void, CString};
use std::mem::ManuallyDrop;
use std::ops::Deref;
-use std::ptr;
/// Rust wrapper around Binder remotable objects.
///
@@ -273,7 +272,7 @@
/// Must be called with a valid pointer to a `T` object. After this call,
/// the pointer will be invalid and should not be dereferenced.
unsafe extern "C" fn on_destroy(object: *mut c_void) {
- ptr::drop_in_place(object as *mut T)
+ Box::from_raw(object as *mut T);
}
/// Called whenever a new, local `AIBinder` object is needed of a specific