Bug #65814 [Opn]: Memory leak in unserialize()

From: Date: Fri, 01 Nov 2013 06:08:41 +0000
Subject: Bug #65814 [Opn]: Memory leak in unserialize()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182542@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65814&edit=1 ID: 65814 Updated by: yohgaki@php.net Reported by: M dot Slowe at kent dot ac dot uk Summary: Memory leak in unserialize() Status: Open Type: Bug Package: Unknown/Other Function Operating System: Linux (Bitnami) PHP Version: 5.4.20 Block user comment: N Private report: N New Comment: This is test script result of my Fedora 19 (x86_64) PHP master -------- Populating object... Serializing... Looping... 19000: 13.71Mb 18000: 13.76Mb 17000: 13.81Mb 16000: 13.85Mb 15000: 13.86Mb 14000: 13.87Mb 13000: 13.88Mb 12000: 13.89Mb 11000: 13.89Mb 10000: 13.90Mb 9000: 13.91Mb 8000: 13.91Mb 7000: 13.91Mb 6000: 13.92Mb 5000: 13.93Mb 4000: 13.93Mb 3000: 13.94Mb 2000: 13.94Mb 1000: 13.94Mb 0: 13.95Mb ---------- PHP-5.4 branch ---------- Populating object... Serializing... Looping... 19000: 13.70Mb 18000: 13.76Mb 17000: 13.81Mb 16000: 13.85Mb 15000: 13.86Mb 14000: 13.87Mb 13000: 13.88Mb 12000: 13.89Mb 11000: 13.89Mb 10000: 13.90Mb 9000: 13.91Mb 8000: 13.91Mb 7000: 13.91Mb 6000: 13.91Mb 5000: 13.92Mb 4000: 13.93Mb 3000: 13.93Mb 2000: 13.94Mb 1000: 13.95Mb 0: 13.95Mb --------- Previous Comments: ------------------------------------------------------------------------ [2013-10-02 15:47:33] M dot Slowe at kent dot ac dot uk 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 this bug report at https://bugs.php.net/bug.php?id=65814&edit=1

« previous php.bugs (#182542) next »