From: M dot Slowe at kent dot ac dot uk Operating system: Linux (Bitnami) PHP version: 5.4.20 Package: Unknown/Other Function Bug Type: Bug Bug description:Memory leak in unserialize()
Description: ------------ It appears that passing a large amount of data (possibly including heavily nested objects) through unserialize() causes a memory leak. I've run into this problem using a SimpleSAMLphp script to keep memcache instances in sync (https://code.google.com/p/simplesamlphp/source/browse/trunk/bin/memcacheSync.php) when syncronizing large caches. The code makes repeated calls to unserialize() with SimpleSAML_Session objects and appears to leak memory within that call. I've noticed that the refcount of the returned objects is 3 but I don't know if that's relevant. Cutting out the call to unserialize() and, instead, just returning the string does not leak the memory. Returning the unserialized object directly after the unserialize() (rather than letting the rest of the function continue) exhibits the leak. The test script doesn't leak anywhere near the amounts I've seen live data leaking (see http://pastebin.com/a15gbNek). Test script: --------------- http://pastebin.com/0cSwhznQ Expected result: ---------------- $ php test.php Populating object... Serializing... Looping... 19000: 7.55Mb 18000: 7.55Mb 17000: 7.55Mb 16000: 7.55Mb 15000: 7.55Mb 14000: 7.55Mb 13000: 7.55Mb 12000: 7.55Mb 11000: 7.55Mb 10000: 7.55Mb 9000: 7.55Mb 8000: 7.55Mb 7000: 7.55Mb 6000: 7.55Mb 5000: 7.55Mb 4000: 7.55Mb 3000: 7.55Mb 2000: 7.55Mb 1000: 7.55Mb 0: 7.55Mb Actual result: -------------- $ php test.php Populating object... Serializing... Looping... 19000: 7.55Mb 18000: 7.57Mb 17000: 7.59Mb 16000: 7.60Mb 15000: 7.60Mb 14000: 7.61Mb 13000: 7.61Mb 12000: 7.62Mb 11000: 7.62Mb 10000: 7.62Mb 9000: 7.62Mb 8000: 7.62Mb 7000: 7.62Mb 6000: 7.62Mb 5000: 7.62Mb 4000: 7.62Mb 3000: 7.62Mb 2000: 7.62Mb 1000: 7.62Mb 0: 7.62Mb -- Edit bug report at https://bugs.php.net/bug.php?id=65814&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65814&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65814&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65814&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65814&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65814&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65814&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65814&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65814&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65814&r=support Expected behavior: https://bugs.php.net/fix.php?id=65814&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65814&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65814&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65814&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65814&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65814&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65814&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65814&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65814&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65814&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65814&r=mysqlcfg