jackylee-ch commented on code in PR #13360:
URL: https://github.com/apache/gluten/pull/13360#discussion_r4310454684


##########
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:
   Could we preserve the original aligned block until the replacement 
allocation succeeds, since a failed aligned_alloc here leaves a 
known-misaligned buffer while reallocateAligned returns true and 
ArrowMemoryPool::Reallocate reports OK?



-- 
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]

Reply via email to