]> granicus.if.org Git - php/commitdiff
Fix #79514: Memory leaks while including unexistent file
authorChristoph M. Becker <cmbecker69@gmx.de>
Fri, 24 Apr 2020 12:51:44 +0000 (14:51 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 24 Apr 2020 16:14:53 +0000 (18:14 +0200)
We have to destroy (un-opened) ZEND_HANDLE_FILENAMEs.

NEWS
Zend/tests/bug79514.phpt [new file with mode: 0644]
Zend/zend_stream.c

diff --git a/NEWS b/NEWS
index 88185d170f788e4c62c688c2c27800fb9f59d8ac..bc5fc665e2c3c64d923a8234fff481dd8cab4321 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP                                                                        NEWS
 - Core:
   . Fixed bug #78434 (Generator yields no items after valid() call). (Nikita)
   . Fixed bug #79477 (casting object into array creates references). (Nikita)
+  . Fixed bug #79514 (Memory leaks while including unexistent file). (cmb,
+    Nikita)
 
 - DOM:
   . Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).
diff --git a/Zend/tests/bug79514.phpt b/Zend/tests/bug79514.phpt
new file mode 100644 (file)
index 0000000..5182489
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #79514 (Memory leaks while including unexistent file)
+--FILE--
+<?php
+$mem1 = memory_get_usage(true);
+for ($i = 0; $i < 100000; $i++) {
+    @include __DIR__ . '/bug79514.doesnotexist';
+}
+$mem2 = memory_get_usage(true);
+var_dump($mem2 - $mem1 < 100000);
+?>
+--EXPECT--
+bool(true)
index 3890248a260522b8e7e6a75089774d9be8e69404..38b145736bea24aa07c4f15e1abc9faf4c616f12 100644 (file)
@@ -238,6 +238,8 @@ ZEND_API int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *
                return 0;
        }
        switch (fh1->type) {
+               case ZEND_HANDLE_FILENAME:
+                       return strcmp(fh1->filename, fh2->filename) == 0;
                case ZEND_HANDLE_FP:
                        return fh1->handle.fp == fh2->handle.fp;
                case ZEND_HANDLE_STREAM: