libbinder_rs: Remove Vec<MaybeUninit<T>> from parcelable.rs
Vec<MaybeUninit<T>> leaks elements if it was partially initialized
and we got an error. Replace it with a safer Vec<UninitType<T>> which
uses either Default or Option::None to initialize elements.
Bug: 278648274
Test: atest atest_integration_test
Change-Id: I2ec97a17b215cb875a48e894eb04832e8a967fca
diff --git a/libs/binder/rust/src/proxy.rs b/libs/binder/rust/src/proxy.rs
index 254efae..036f6b4 100644
--- a/libs/binder/rust/src/proxy.rs
+++ b/libs/binder/rust/src/proxy.rs
@@ -439,6 +439,14 @@
impl SerializeArray for SpIBinder {}
impl Deserialize for SpIBinder {
+ type UninitType = Option<Self>;
+ fn uninit() -> Self::UninitType {
+ Self::UninitType::default()
+ }
+ fn from_init(value: Self) -> Self::UninitType {
+ Some(value)
+ }
+
fn deserialize(parcel: &BorrowedParcel<'_>) -> Result<SpIBinder> {
parcel.read_binder().transpose().unwrap_or(Err(StatusCode::UNEXPECTED_NULL))
}