LuciferYang commented on code in PR #13360:
URL: https://github.com/apache/gluten/pull/13360#discussion_r4321966099
##########
cpp/core/memory/MemoryAllocator.cc:
##########
@@ -172,7 +173,20 @@ bool StdMemoryAllocator::reallocateAligned(void* p,
uint64_t alignment, int64_t
auto aligned = ROUND_TO_LINE(static_cast<uint64_t>(newSize), alignment);
if (aligned <= size) {
// shrink-to-fit
- return reallocate(p, size, aligned, out);
+ if (!reallocate(p, size, aligned, out)) {
+ return false;
+ }
+ // realloc only guarantees fundamental alignment, so the moved block may
not be aligned to alignment.
+ if (reinterpret_cast<uintptr_t>(*out) % alignment != 0) {
+ void* alignedP = std::aligned_alloc(alignment, aligned);
+ // p is already released, so keep the moved block rather than fail if
this allocation fails.
+ if (alignedP != nullptr) {
Review Comment:
Thanks, fixed in 7ae7227f6. The shrink branch now allocates the aligned
block before calling realloc, so if that allocation fails it returns false and
the original block is left as is. When realloc keeps the block aligned, the
spare block is freed and nothing is copied.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]