Skip to content

Commit

Permalink
Fix panic when dropping vectors using ZeroCopyBuffer (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex committed Jul 12, 2024
1 parent 0ae80ab commit e137492
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ impl Drop for DartCObject {
struct MyVisitor<'a>(&'a DartNativeTypedData);
impl DartTypedDataTypeVisitor for MyVisitor<'_> {
fn visit<T: DartTypedDataTypeTrait>(&self) {
if self.0.values.is_null() {
return;
}
let _ = unsafe {
Vec::from_raw_parts(
self.0.values as *mut T,
Expand Down
5 changes: 5 additions & 0 deletions tests/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u64>> = ZeroCopyBuffer(vec![]);
let b = a.into_dart();
drop(b);

println!("all done!");
}

Expand Down

0 comments on commit e137492

Please sign in to comment.