-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GLUTEN-8476][VL] Fix allocate and free memory #8477
Conversation
2b5814b
to
8ba547b
Compare
cpp/core/memory/MemoryAllocator.cc
Outdated
@@ -172,14 +172,18 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t | |||
return false; | |||
} | |||
memcpy(reallocatedP, p, std::min(size, newSize)); | |||
std::free(p); | |||
if (p != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add the check of p at beginning
if (newSize <= 0 && p==nullptr) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Will switch the && to ||
cpp/core/memory/MemoryAllocator.cc
Outdated
*out = reallocatedP; | ||
bytes_ += (newSize - size); | ||
return true; | ||
} | ||
|
||
bool StdMemoryAllocator::free(void* p, int64_t size) { | ||
std::free(p); | ||
if (p != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to
if (p==nullptr) return false;
6a19100
to
d3c9231
Compare
cpp/core/memory/MemoryAllocator.cc
Outdated
@@ -157,7 +157,7 @@ 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) { | |||
if (newSize <= 0) { | |||
if (newSize <= 0 || p == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we throw exceptions (and other changes as well)? Since it's not usual to have a nullptr passed in for such functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could refer to the macros in
#define GLUTEN_CHECK(expr, errMessage) \ |
d3c9231
to
a11df59
Compare
cpp/core/memory/MemoryAllocator.cc
Outdated
@@ -157,6 +157,9 @@ 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) { | |||
if (p == nullptr) { | |||
throw gluten::GlutenException("p is nullptr"); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hongze means to use the Macro:
GLUTEN_CHECK(p!=nullptr,"reallocate with nullptr");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thank you!
cpp/core/memory/MemoryAllocator.cc
Outdated
@@ -179,6 +182,9 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t | |||
} | |||
|
|||
bool StdMemoryAllocator::free(void* p, int64_t size) { | |||
if (p == nullptr) { | |||
throw gluten::GlutenException("p is nullptr"); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLUTEN_CHECK(p!=nullptr, "free with nullptr");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thank you!
a11df59
to
ef83329
Compare
What changes were proposed in this pull request?
Allocate and free memory in the same module
(Please fill in changes proposed in this fix)
(Fixes: #8476)