File tree Expand file tree Collapse file tree 3 files changed +13
-13
lines changed
Expand file tree Collapse file tree 3 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 55
66#![ allow( clippy:: unwrap_used) ]
77
8+ use std:: sync:: LazyLock ;
9+
810use arrow_schema:: DataType ;
911use arrow_schema:: ffi:: FFI_ArrowSchema ;
1012use futures:: executor:: block_on;
11- use std:: sync:: LazyLock ;
1213use vortex:: array:: IntoArray ;
1314use vortex:: array:: arrays:: PrimitiveArray ;
1415use vortex:: array:: session:: ArraySession ;
Original file line number Diff line number Diff line change @@ -60,10 +60,18 @@ async fn export_primitive(
6060 ctx : & mut CudaExecutionCtx ,
6161) -> VortexResult < ArrowArray > {
6262 unsafe extern "C" fn release ( array : * mut ArrowArray ) {
63- // SAFETY: this is only safe if the caller provides a valid pointer to an `ArrowArray`.
64- drop ( unsafe { Box :: from_raw ( array) } ) ;
65- }
63+ // SAFETY: this is only safe if we're dropping an ArrowArray that was created from Rust
64+ // code. This is necessary to ensure that the fields inside the CudaPrivateData
65+ // get dropped to free native/GPU memory.
66+ unsafe {
67+ let private_data_ptr =
68+ std:: ptr:: replace ( & raw mut ( * array) . private_data , std:: ptr:: null_mut ( ) ) ;
69+ drop ( Box :: from_raw ( private_data_ptr. cast :: < CudaPrivateData > ( ) ) ) ;
6670
71+ // update the release function to NULL to avoid any possibility of double-frees.
72+ ( * array) . release = None ;
73+ }
74+ }
6775 let len = array. len ( ) ;
6876 let PrimitiveArrayParts {
6977 buffer, validity, ..
Original file line number Diff line number Diff line change @@ -103,15 +103,6 @@ impl ArrowArray {
103103 }
104104}
105105
106- impl Drop for ArrowArray {
107- fn drop ( & mut self ) {
108- // SAFETY: this is only safe if we're dropping an ArrowArray that was created from Rust
109- // code. This is necessary to ensure that the fields inside of the CudaPrivateData
110- // get dropped to free native/GPU memory.
111- drop ( unsafe { Box :: from_raw ( self . private_data . cast :: < CudaPrivateData > ( ) ) } )
112- }
113- }
114-
115106#[ expect(
116107 unused,
117108 reason = "cuda_stream and cuda_buffers need to have deferred drop"
You can’t perform that action at this time.
0 commit comments