ID: 41127
Updated by: [EMAIL PROTECTED]
Reported By: ktk at bigfoot dot com
-Status: Open
+Status: Assigned
Bug Type: LDAP related
Operating System: Slackware GNU/Linux
PHP Version: 5.2.1
-Assigned To:
+Assigned To: cardoe
Previous Comments:
------------------------------------------------------------------------
[2007-04-17 22:26:30] ktk at bigfoot dot com
Description:
------------
PHP "leaks" memory in the ldap_{first|next}_attribute() functions.
Interestingly, the ldap_get_attributes() function does not leak.
I put "leaks" in quotes because the leak() function does not detect the
issue; presumably, the memory is programmatically freed, just not until
PHP exits.
If one does something like:
while (true) {
$s = ldap_search($link, $base, $filter, $atts);
for ($e = ldap_first_entry($link, $s); $e != false;
$e = ldap_next_entry($link, $e)) {
for ($a = ldap_first_attribute($link, $e, $ber); $a;
$a = ldap_next_attribute($link, $e, $ber)) { }
}
ldap_free_result($s);
}
then PHP will eat all available memory and bomb with a memory
allocation error. Unbinding and re-binding has no effect.
Reproduce code:
---------------
A working 51-line script that shows memory allocation versus iteration
count can be found at this url:
http://enterprise.bidmc.harvard.edu/private/php-bugs/ldap-leak-test.php
There are a few variables you can set/tweak at the top to get it to
point at whatever LDAP server you have handy. Choosing a search filter
that returns a dozen or so entries is ideal for showing the runaway
memory. You can also change the "$fail" variable from True to False,
which will stop the leak by way of using the roughly-equivalent function
ldap_get_attributes().
Expected result:
----------------
PHP's memory subsystem should collect and re-use the freed memory.
After some number of iterations of the test script (typically 100 to
500) the results reported by memory_get_usage() should remain stable.
Actual result:
--------------
The results reported by memory_get_usage() increase fairly linearly
with each iteration until memory_limit is reached, whence the script
bombs.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41127&edit=1