mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
fix: Check for null pointer returned by ValueSerializer::Release
(#1599)
* Check for null ptr during release * Add to test * Reorder
This commit is contained in:
parent
909f6d3afa
commit
eb29f6bd8c
2 changed files with 12 additions and 8 deletions
|
@ -536,14 +536,17 @@ impl<'a> ValueSerializer<'a> {
|
||||||
&mut ptr,
|
&mut ptr,
|
||||||
&mut size,
|
&mut size,
|
||||||
);
|
);
|
||||||
Vec::from_raw_parts(
|
let capacity = self
|
||||||
ptr,
|
.value_serializer_heap
|
||||||
size,
|
.buffer_size
|
||||||
self
|
.swap(0, std::sync::atomic::Ordering::Relaxed);
|
||||||
.value_serializer_heap
|
if ptr.is_null() {
|
||||||
.buffer_size
|
return Vec::new();
|
||||||
.swap(0, std::sync::atomic::Ordering::Relaxed),
|
}
|
||||||
)
|
assert!(size <= capacity);
|
||||||
|
// SAFETY: ptr is non-null, was allocated by us in `v8__ValueSerializer__Delegate__ReallocateBufferMemory`, and
|
||||||
|
// the capacity is correctly updated during reallocation. Size is asserted to be valid above.
|
||||||
|
Vec::from_raw_parts(ptr, size, capacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8070,6 +8070,7 @@ fn value_serializer_and_deserializer() {
|
||||||
value_serializer.write_double(55.44);
|
value_serializer.write_double(55.44);
|
||||||
value_serializer.write_uint32(22);
|
value_serializer.write_uint32(22);
|
||||||
buffer = value_serializer.release();
|
buffer = value_serializer.release();
|
||||||
|
assert_eq!(value_serializer.release(), Vec::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut double: f64 = 0.0;
|
let mut double: f64 = 0.0;
|
||||||
|
|
Loading…
Reference in a new issue