From: nikic Operating system: PHP version: Irrelevant Package: *General Issues Bug Type: Bug Bug description:Memory leak in parse_ini_file when specifying invalid scanner mode
Description: ------------ parse_ini_file('emptyFile', false, 26); Leaks: Warning: Invalid scanner mode in /home/nikic/dev/my- fuzzer/reproduceCode5_memoryLeak.php on line 3 [Tue Feb 14 18:36:56 2012] Script: 'reproduceCode5_memoryLeak.php' /home/nikic/dev/php-src/main/streams/plain_wrapper.c(910) : Freeing 0xB780BE94 (36 bytes), script=reproduceCode5_memoryLeak.php [Tue Feb 14 18:36:56 2012] Script: 'reproduceCode5_memoryLeak.php' /home/nikic/dev/php-src/Zend/zend_stream.c(280) : Freeing 0xB780C908 (32 bytes), script=reproduceCode5_memoryLeak.php === Total 2 memory leaks detected === The reason is that the file handle is not closed correctly. I was able to fix it using this simple patch: diff --git a/Zend/zend_ini_scanner.c b/Zend/zend_ini_scanner.c index 85fc74d..3b4e217 100644 --- a/Zend/zend_ini_scanner.c +++ b/Zend/zend_ini_scanner.c @@ -230,9 +230,12 @@ int zend_ini_open_file_for_scanning(zend_file_handle *fh, i char *buf; size_t size; - if (zend_stream_fixup(fh, &buf, &size TSRMLS_CC) == FAILURE || - init_ini_scanner(scanner_mode, fh TSRMLS_CC) == FAILURE - ) { + if (zend_stream_fixup(fh, &buf, &size TSRMLS_CC) == FAILURE) { + return FAILURE; + } + + if (init_ini_scanner(scanner_mode, fh TSRMLS_CC) == FAILURE) { + zend_file_handle_dtor(fh TSRMLS_CC); return FAILURE; } -- Edit bug report at https://bugs.php.net/bug.php?id=61087&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61087&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61087&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61087&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61087&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61087&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61087&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61087&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61087&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61087&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61087&r=support Expected behavior: https://bugs.php.net/fix.php?id=61087&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61087&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61087&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61087&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61087&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61087&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61087&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61087&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61087&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61087&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61087&r=mysqlcfg