diff --git a/src/ffi.rs b/src/ffi.rs index b6276b5..054b064 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -182,6 +182,9 @@ impl Drop for DartCObject { struct MyVisitor<'a>(&'a DartNativeTypedData); impl DartTypedDataTypeVisitor for MyVisitor<'_> { fn visit(&self) { + if self.0.values.is_null() { + return; + } let _ = unsafe { Vec::from_raw_parts( self.0.values as *mut T, diff --git a/tests/containers.rs b/tests/containers.rs index 6cbc481..73504c8 100644 --- a/tests/containers.rs +++ b/tests/containers.rs @@ -245,6 +245,11 @@ fn main() { assert!(isolate.post(vec![vec![10u8]])); + // Test case to verify that dropping vectors using ZeroCopyBuffer no longer causes a panic + let a: ZeroCopyBuffer> = ZeroCopyBuffer(vec![]); + let b = a.into_dart(); + drop(b); + println!("all done!"); }