Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Correctly deallocate external typed data #63

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install nightly toolchain
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: stable
override: true

# - name: Install valgrind
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install valgrind
run: |
sudo apt update && sudo apt install -y libclang-dev libc6-dbg \
&& wget -O valgrind.tar.bz2 https://sourceware.org/pub/valgrind/valgrind-3.19.0.tar.bz2 \
&& wget -O valgrind.tar.bz2 https://sourceware.org/pub/valgrind/valgrind-3.23.0.tar.bz2 \
&& mkdir valgrind && tar -xvjf valgrind.tar.bz2 -C valgrind --strip-components=1 \
&& cd valgrind && ./configure && make && sudo make install

Expand Down
10 changes: 4 additions & 6 deletions src/into_dart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
};
}

let mut vec = ManuallyDrop::new(vec_from_rust);
let mut vec = vec_from_rust;
vec.shrink_to_fit();
let length = vec.len();
assert_eq!(length, vec.capacity());
Expand All @@ -191,7 +191,7 @@ where
ty: T::dart_typed_data_type(),
length: length as isize,
data: ptr as *mut u8,
peer: ptr as *mut c_void,
peer: Box::into_raw(Box::new(vec)).cast(),
callback: T::function_pointer_of_free_zero_copy_buffer(),
},
},
Expand Down Expand Up @@ -253,12 +253,10 @@ macro_rules! dart_typed_data_type_trait_impl {
#[doc(hidden)]
#[no_mangle]
pub(crate) unsafe extern "C" fn $free_zero_copy_buffer_func(
isolate_callback_data: *mut c_void,
_isolate_callback_data: *mut c_void,
peer: *mut c_void,
) {
let len = (isolate_callback_data as isize) as usize;
let ptr = peer as *mut $rust_type;
drop(Vec::from_raw_parts(ptr, len, len));
drop(Box::from_raw(peer.cast::<Vec<$rust_type>>()));
}
)+

Expand Down
Loading