Skip to content

Commit

Permalink
fix realloc OOM behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMakeev committed Oct 13, 2023
1 parent 8937410 commit 8e00364
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SmMalloc/smmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,14 @@ class Allocator
// alloc new memory block and move memory
void* p2 = Alloc(bytesCount, alignment);

if (p2 == nullptr)
{
// realloc
// On failure, returns a null pointer.
// The original pointer ptr remains valid and may need to be deallocated with free or realloc.
return nullptr;
}

// Assume that p is the pointer that is allocated by passing the zero size. No preserve memory conents is requried.
if (IsReadable(p))
{
Expand Down

0 comments on commit 8e00364

Please sign in to comment.