zhouyuan commented on code in PR #13668:
URL: https://github.com/apache/gluten/pull/13668#discussion_r4640901935


##########
cpp/core/memory/MemoryAllocator.cc:
##########
@@ -166,9 +166,21 @@ bool StdMemoryAllocator::reallocate(void* p, int64_t size, 
int64_t newSize, void
 
 bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, 
int64_t size, int64_t newSize, void** out) {
   GLUTEN_CHECK(p != nullptr, "reallocate with nullptr");
-  if (newSize <= 0) {
+  if (newSize < 0) {
     return false;
   }
+  if (newSize == 0) {
+    // Keep a freeable, aligned pointer without relying on realloc(p, 0) or 
aligned_alloc(alignment, 0).
+    // The allocation has zero logical size, so only the old size is removed 
from accounting.
+    void* empty = std::aligned_alloc(alignment, alignment);

Review Comment:
   in a aligned_alloc we will add 64 bytes, but in line 179 it will only free 
the original size.
   would this introduce a memory leakage? 



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