Skip to content

Commit

Permalink
#268: Move delete to the bottom of deserializeType function
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Sep 30, 2024
1 parent 35e050c commit 7f78f73
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/checkpoint/dispatch/dispatch.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,17 @@ deserializeType(SerialByteType* data, SerialByteType* allocBuf) {
auto prefix_struct = PrefixedType(prefix_buf);
// Disable memory check during first unpacking.
// Unpacking BaseType will always result in memory amount missmatch between serialization/deserialization
auto* prefix =
Standard::unpack<PrefixedType, UnpackerBuffer<buffer::UserBuffer>>(&prefix_struct, data, false);
delete prefix_buf;
auto* prefix = Standard::unpack<PrefixedType, UnpackerBuffer<buffer::UserBuffer>>(&prefix_struct, data, false);

validatePrefix<BaseType>(prefix->prefix_);

// allocate memory based on the readed TypeIdx
auto mem = allocBuf ? allocBuf : vrt::objregistry::allocateConcreteType<BaseType>(prefix->prefix_);
auto t_buf = vrt::objregistry::constructConcreteType<BaseType>(prefix->prefix_, mem);
auto prefixed = PrefixedType(t_buf);
auto* traverser =
Standard::unpack<PrefixedType, UnpackerBuffer<buffer::UserBuffer>>(&prefixed, data);
auto* traverser = Standard::unpack<PrefixedType, UnpackerBuffer<buffer::UserBuffer>>(&prefixed, data);

delete prefix_buf;
return static_cast<T*>(traverser->target_);
}

Expand Down

0 comments on commit 7f78f73

Please sign in to comment.