Browse Source

Handle out of memory/bad size situation gracefully, without getting into loop

PEAR_1_4DEV
Stanislav Malyshev 23 years ago
parent
commit
9731d9f303
  1. 10
      Zend/zend_mm.c

10
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);
}

Loading…
Cancel
Save