From 5e8dfa3a673998ebab2ed0d992d426e9d130ad73 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 16 Dec 2020 12:50:06 +0000 Subject: Implement Drop for WpIBinder, to avoid memory leak. Bug: 175584883 Test: mm Change-Id: I741187bb83b1f6b353df575633a64cf7aeb4112a --- libs/binder/rust/src/proxy.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/binder/rust/src/proxy.rs b/libs/binder/rust/src/proxy.rs index 9d612a43f4..17af0992e2 100644 --- a/libs/binder/rust/src/proxy.rs +++ b/libs/binder/rust/src/proxy.rs @@ -416,6 +416,16 @@ impl WpIBinder { } } +impl Drop for WpIBinder { + fn drop(&mut self) { + unsafe { + // Safety: WpIBinder always holds a valid `AIBinder_Weak` pointer, so we + // know this pointer is safe to pass to `AIBinder_Weak_delete` here. + sys::AIBinder_Weak_delete(self.0); + } + } +} + /// Rust wrapper around DeathRecipient objects. #[repr(C)] pub struct DeathRecipient { -- cgit v1.2.3-59-g8ed1b