Avoid a crash in realloc() if the allocation of the new block failed. Return NULL instead.
Someone please review. Should errno be set to ENOMEM here? git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21903 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -285,6 +285,11 @@ realloc(void *ptr, size_t size)
|
|||||||
|
|
||||||
// Allocate a new block of size sz.
|
// Allocate a new block of size sz.
|
||||||
void *buffer = malloc(size);
|
void *buffer = malloc(size);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
// Allocation failed, free old block and return
|
||||||
|
free(ptr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the contents of the original object
|
// Copy the contents of the original object
|
||||||
// up to the size of the new block.
|
// up to the size of the new block.
|
||||||
|
|||||||
Reference in New Issue
Block a user