mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -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 size,
|
||||
);
|
||||
Vec::from_raw_parts(
|
||||
ptr,
|
||||
size,
|
||||
self
|
||||
.value_serializer_heap
|
||||
.buffer_size
|
||||
.swap(0, std::sync::atomic::Ordering::Relaxed),
|
||||
)
|
||||
let capacity = self
|
||||
.value_serializer_heap
|
||||
.buffer_size
|
||||
.swap(0, std::sync::atomic::Ordering::Relaxed);
|
||||
if ptr.is_null() {
|
||||
return Vec::new();
|
||||
}
|
||||
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_uint32(22);
|
||||
buffer = value_serializer.release();
|
||||
assert_eq!(value_serializer.release(), Vec::new());
|
||||
}
|
||||
|
||||
let mut double: f64 = 0.0;
|
||||
|
|
Loading…
Reference in a new issue