Skip to content
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

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

jkhaliqi
Copy link
Contributor

@jkhaliqi jkhaliqi commented Jan 8, 2025

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)

@github-actions github-actions bot added the VELOX label Jan 8, 2025
Copy link

github-actions bot commented Jan 8, 2025

#8476

@@ -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) {
Copy link
Contributor

@FelixYBW FelixYBW Jan 9, 2025

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

Copy link
Contributor Author

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

*out = reallocatedP;
bytes_ += (newSize - size);
return true;
}

bool StdMemoryAllocator::free(void* p, int64_t size) {
std::free(p);
if (p != nullptr) {
Copy link
Contributor

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;

@jkhaliqi jkhaliqi force-pushed the jk_cve_allocate branch 2 times, most recently from 6a19100 to d3c9231 Compare January 10, 2025 04:51
@@ -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) {
Copy link
Member

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.

Copy link
Member

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) \
if needed

@@ -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");
}
Copy link
Contributor

@FelixYBW FelixYBW Jan 10, 2025

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");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thank you!

@@ -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");
}
Copy link
Contributor

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");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thank you!

@FelixYBW FelixYBW merged commit 4bdda17 into apache:main Jan 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[VL] Security Voliations Allocate and free memory in the same module
3 participants