Skip to content

Commit

Permalink
Use heapAlignSize in newAlloc
Browse files Browse the repository at this point in the history
Summary:
The `size` parameter passed to these two functions is not the actual final
size in the heap, as the heap may round the size up if it isn't a multiple of
`HeapAlign` (which happens to be 8).

This was a quite rare occurrence, since most of our objects happen to have
a size that is a multiple of 8 anyway; however, it can happen, and if it did,
`freeAlloc` would try to subtract more bytes than were added, resulting in an assert.

Reviewed By: neildhar

Differential Revision: D25078476

fbshipit-source-id: cc7c0c824f3d41fe3ddc8ec6a7a1d34b96d896f0
  • Loading branch information
Riley Dulin authored and facebook-github-bot committed Nov 19, 2020
1 parent 98d29bd commit 662cb35
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/hermes/VM/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ T *Runtime::makeAFixed(Args &&... args) {
T *ptr = heap_.makeA<T, true /* fixedSize */, hasFinalizer, longLived>(
sz, std::forward<Args>(args)...);
#ifdef HERMES_ENABLE_ALLOCATION_LOCATION_TRACES
heap_.getAllocationLocationTracker().newAlloc(ptr, sz);
heap_.getAllocationLocationTracker().newAlloc(ptr, heapAlignSize(sz));
#endif
return ptr;
}
Expand All @@ -1675,7 +1675,7 @@ T *Runtime::makeAVariable(uint32_t size, Args &&... args) {
T *ptr = heap_.makeA<T, false /* fixedSize */, hasFinalizer, longLived>(
size, std::forward<Args>(args)...);
#ifdef HERMES_ENABLE_ALLOCATION_LOCATION_TRACES
heap_.getAllocationLocationTracker().newAlloc(ptr, size);
heap_.getAllocationLocationTracker().newAlloc(ptr, heapAlignSize(size));
#endif
return ptr;
}
Expand Down

0 comments on commit 662cb35

Please sign in to comment.