cvs: ZendEngine2 / zend_mm.c
| From: | Stanislav Malyshev | Date: | Thu, 04 Mar 2004 09:18:06 +0000 |
| Subject: | cvs: ZendEngine2 / zend_mm.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-2440@lists.php.net to get a copy of this message | ||
stas Thu Mar 4 04:18:06 2004 EDT
Modified files:
/ZendEngine2 zend_mm.c
Log:
Handle out of memory/bad size situation gracefully, without getting into loop
http://cvs.php.net/diff.php/ZendEngine2/zend_mm.c?r1=1.28&r2=1.29&ty=u
Index: ZendEngine2/zend_mm.c
diff -u ZendEngine2/zend_mm.c:1.28 ZendEngine2/zend_mm.c:1.29
--- ZendEngine2/zend_mm.c:1.28 Thu Jan 8 12:31:47 2004
+++ ZendEngine2/zend_mm.c Thu Mar 4 04:18:05 2004
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_mm.c,v 1.28 2004/01/08 17:31:47 sniper Exp $ */
+/* $Id: zend_mm.c,v 1.29 2004/03/04 09:18:05 stas Exp $ */
#include "zend.h"
#include "zend_mm.h"
@@ -318,9 +318,15 @@
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);
}