summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2004-03-04 09:18:05 +0000
committerStanislav Malyshev <stas@php.net>2004-03-04 09:18:05 +0000
commit9731d9f30343b2efae4d3298520eb943f09c8c9c (patch)
tree6b734422ce279d4566e569280bbee9becbf55209
parent62670bd1aff978a77bdd9d8495618851e8f1d13c (diff)
downloadphp-git-9731d9f30343b2efae4d3298520eb943f09c8c9c.tar.gz
Handle out of memory/bad size situation gracefully, without getting into loop
-rw-r--r--Zend/zend_mm.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Zend/zend_mm.c b/Zend/zend_mm.c
index 1dc57ba0c5..71a24c11ea 100644
--- a/Zend/zend_mm.c
+++ b/Zend/zend_mm.c
@@ -318,9 +318,15 @@ zend_mm_finished_searching_for_block:
if (!best_fit) {
if (true_size > (heap->block_size - ZEND_MM_ALIGNED_SEGMENT_SIZE - ZEND_MM_ALIGNED_HEADER_SIZE)) {
/* Make sure we add a memory block which is big enough */
- zend_mm_add_memory_block(heap, true_size + ZEND_MM_ALIGNED_SEGMENT_SIZE + ZEND_MM_ALIGNED_HEADER_SIZE);
+ if (zend_mm_add_memory_block(heap, true_size + ZEND_MM_ALIGNED_SEGMENT_SIZE + ZEND_MM_ALIGNED_HEADER_SIZE)) {
+ zend_error(E_ERROR, "Out of memory: cannot allocate %d bytes!", true_size);
+ return NULL;
+ }
} else {
- zend_mm_add_memory_block(heap, heap->block_size);
+ if (zend_mm_add_memory_block(heap, heap->block_size)) {
+ zend_error(E_ERROR, "Out of memory: cannot allocate %d bytes!", heap->block_size);
+ return NULL;
+ }
}
return zend_mm_alloc(heap, size);
}