Skip to content

Commit

Permalink
Fix array from_ptr drops.
Browse files Browse the repository at this point in the history
  • Loading branch information
azteca1998 committed Feb 14, 2025
1 parent 207ff9e commit ac87223
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ impl Value {
);
let num_elems = (end_offset_value - start_offset_value) as usize;

// Drop prefix elements.
if should_drop {
if *ref_count == 0 {
// Drop prefix elements.
for i in 0..start_offset_value {
let cur_elem_ptr =
NonNull::new(array_ptr.byte_add(elem_stride * i as usize))
Expand Down Expand Up @@ -675,8 +675,8 @@ impl Value {
)?);
}

// Drop suffix elements.
if should_drop {
if *ref_count == 0 {
// Drop suffix elements.
let array_max_len = array_ptr
.byte_sub(refcount_offset - size_of::<u32>())
.cast::<u32>()
Expand All @@ -694,9 +694,8 @@ impl Value {
should_drop,
)?);
}
}

if *ref_count == 0 {
// Free array storage.
libc_free(array_ptr.byte_sub(refcount_offset).cast());
libc_free(array_ptr_ptr.cast());
}
Expand Down

0 comments on commit ac87223

Please sign in to comment.