Skip to content

[GLUTEN-8476][VL] Fix allocate and free memory#8477

Merged
FelixYBW merged 1 commit intoapache:mainfrom
jkhaliqi:jk_cve_allocate
Jan 10, 2025
Merged

[GLUTEN-8476][VL] Fix allocate and free memory#8477
FelixYBW merged 1 commit intoapache:mainfrom
jkhaliqi:jk_cve_allocate

Conversation

@jkhaliqi
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 8, 2025

#8476

Comment thread cpp/core/memory/MemoryAllocator.cc Outdated
}
memcpy(reallocatedP, p, std::min(size, newSize));
std::free(p);
if (p != nullptr) {
Copy link
Copy Markdown
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
Copy Markdown
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 ||

Comment thread cpp/core/memory/MemoryAllocator.cc Outdated

bool StdMemoryAllocator::free(void* p, int64_t size) {
std::free(p);
if (p != nullptr) {
Copy link
Copy Markdown
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
Comment thread cpp/core/memory/MemoryAllocator.cc Outdated

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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread cpp/core/memory/MemoryAllocator.cc Outdated
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
Copy Markdown
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
Copy Markdown
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!

Comment thread cpp/core/memory/MemoryAllocator.cc Outdated
bool StdMemoryAllocator::free(void* p, int64_t size) {
if (p == nullptr) {
throw gluten::GlutenException("p is nullptr");
}
Copy link
Copy Markdown
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
Copy Markdown
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
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