Skip to content

Commit

Permalink
fix: undefined behavior in schema ffi (#582) (#583)
Browse files Browse the repository at this point in the history
Closes #580

Signed-off-by: roee88 <roee88@gmail.com>

Co-authored-by: Roee Shlomo <roee88@gmail.com>
  • Loading branch information
alamb and roee88 authored Jul 25, 2021
1 parent 9dd0aec commit 952cae4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl FFI_ArrowSchema {
pub fn try_new(format: &str, children: Vec<FFI_ArrowSchema>) -> Result<Self> {
let mut this = Self::empty();

let mut children_ptr = children
let children_ptr = children
.into_iter()
.map(Box::new)
.map(Box::into_raw)
Expand All @@ -161,11 +161,14 @@ impl FFI_ArrowSchema {
this.format = CString::new(format).unwrap().into_raw();
this.release = Some(release_schema);
this.n_children = children_ptr.len() as i64;
this.children = children_ptr.as_mut_ptr();

let private_data = Box::new(SchemaPrivateData {
let mut private_data = Box::new(SchemaPrivateData {
children: children_ptr,
});

// intentionally set from private_data (see https://github.com/apache/arrow-rs/issues/580)
this.children = private_data.children.as_mut_ptr();

this.private_data = Box::into_raw(private_data) as *mut c_void;

Ok(this)
Expand Down

0 comments on commit 952cae4

Please sign in to comment.