cvs: ZendEngine2 / zend_alloc.c /tests bug44069.phpt

[email protected] ("Dmitry Stogov")
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1203000136@cvsserver>
dmitry		Thu Feb 14 14:42:16 2008 UTC

  Modified files:              
    /ZendEngine2	zend_alloc.c 
    /ZendEngine2/tests	bug44069.phpt 
  Log:
  Fixed bug #44069 (Huge memory usage with concatenation using . instead of .=)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.211&r2=1.212&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.211 ZendEngine2/zend_alloc.c:1.212
--- ZendEngine2/zend_alloc.c:1.211	Thu Jan 24 12:21:48 2008
+++ ZendEngine2/zend_alloc.c	Thu Feb 14 14:42:16 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.211 2008/01/24 12:21:48 dmitry Exp $ */
+/* $Id: zend_alloc.c,v 1.212 2008/02/14 14:42:16 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_alloc.h"
@@ -1784,6 +1784,7 @@
 	size_t remaining_size;
 	size_t segment_size;
 	zend_mm_segment *segment;
+	int keep_rest = 0;
 
 	if (EXPECTED(ZEND_MM_SMALL_SIZE(true_size))) {
 		size_t index = ZEND_MM_BUCKET_INDEX(true_size);
@@ -1852,6 +1853,7 @@
 			   segment must have header "size" and trailer "guard" block */
 			segment_size = true_size + ZEND_MM_ALIGNED_SEGMENT_SIZE + ZEND_MM_ALIGNED_HEADER_SIZE;
 			segment_size = (segment_size + (heap->block_size-1)) & ~(heap->block_size-1);
+			keep_rest = 1;
 		} else {
 			segment_size = heap->block_size;
 		}
@@ -1931,7 +1933,11 @@
 		ZEND_MM_BLOCK(new_free_block, ZEND_MM_FREE_BLOCK, remaining_size);
 
 		/* add the new free block to the free list */
-		zend_mm_add_to_free_list(heap, new_free_block);
+		if (EXPECTED(!keep_rest)) {
+			zend_mm_add_to_free_list(heap, new_free_block);
+		} else {
+			zend_mm_add_to_rest_list(heap, new_free_block);
+		}
 	}
 
 	ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 1);
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug44069.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/bug44069.phpt
diff -u /dev/null ZendEngine2/tests/bug44069.phpt:1.2
--- /dev/null	Thu Feb 14 14:42:16 2008
+++ ZendEngine2/tests/bug44069.phpt	Thu Feb 14 14:42:16 2008
@@ -0,0 +1,21 @@
+--TEST--
+Bug #44069 (Huge memory usage with concatenation using . instead of .=)
+--FILE--
+<?php
+$array = array();
+$newstring = "";
+$string = str_repeat('This is a teststring.', 50);
+for($i = 1; $i <= 2000; $i++)
+{
+//	$newstring .= $string; //This uses an expected amount of mem.
+	$newstring = $newstring . $string; //This uses very much mem.
+
+	for($j = 1; $j <= 10; $j++)
+	{
+		$array[] = 'test';
+	}
+}
+echo "ok\n";
+?>
+--EXPECT--
+ok
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.