From: jmy at morgontech dot com
Operating system: CentOS 5.3 / Kernel 2.6.18-128
PHP version: 5.3.0
PHP Bug Type: Arrays related
Bug description: unsetting array member inside uksort function causes 1.5GB
memory exhaustion
Description:
------------
In an attempt to cull some unneeded array elements from within a
user-defined function for uksort(), I came across a very odd memory
exhaustion issue where array.c collapses under a sudden 1.5GB memory
allocation attempt.
I realize this may not be the best way to accomplish my goal, but am
pretty sure the memory exhaustion shouldn't be happening, regardless.
Reproduce code:
---------------
<?php
$sortOrder = Array(281, 830, 580, 541, 838, 839, 702, 625, 102, 234, 532,
317, 859, 738, 17, 350);
$myArray = Array(
830 => 'eightthirty',
317 => 'threeseventeen',
102 => 'oneohtwo',
281 => 'twoeightyone',
14 => 'fourteen',
580 => 'fiveeighty',
541 => 'fivefourtyone',
350 => 'threefifty',
838 => 'eightthirtyeight',
839 => 'eightthirtynine',
702 => 'sevenohtwo',
625 => 'sixtwentyfive',
234 => 'twothreefour',
532 => 'fivethirtytwo',
859 => 'eightfiftynine',
738 => 'seventhirtyeight',
17 => 'seventeen'
);
function sortByOrder($a, $b) {
global $sortOrder;
global $myArray;
if (!in_array($a, $sortOrder)) {
unset($myArray[$a]);
return 1;
}
if (!in_array($b, $sortOrder)) {
return -1;
}
return array_search($a, $sortOrder) - array_search($b,
$sortOrder);
}
uksort($myArray, 'sortByOrder');
print_r($myArray);
?>
Expected result:
----------------
Expected result is an array sorted to match $sortOrder
Actual result:
--------------
Fatal error: Allowed memory size of 16777216 bytes exhausted at
/root/source/php-5.3.0/ext/standard/array.c:694 (tried to allocate
1515870810 bytes) in /path/to/uksort_memory.php on line 38
--
Edit bug report at http://bugs.php.net/?id=49896&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49896&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49896&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49896&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49896&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49896&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49896&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49896&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49896&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49896&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49896&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49896&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49896&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49896&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49896&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49896&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49896&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49896&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49896&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49896&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49896&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49896&r=mysqlcfg