]> granicus.if.org Git - php/commitdiff
- Fixed memory leak when calling the Finfo constructor twice
authorFelipe Pena <felipe@php.net>
Wed, 23 Nov 2011 01:20:49 +0000 (01:20 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 23 Nov 2011 01:20:49 +0000 (01:20 +0000)
NEWS
ext/fileinfo/fileinfo.c
ext/fileinfo/tests/finfo_open_002.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9402ccdf54a983bae81cf4bc20b0a4d64ddb6017..384796735ea5c7c677ad9e75e96c661e123e1748 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,7 @@ PHP                                                                        NEWS
     
 - Fileinfo:
   . Fixed possible memory leak in finfo_open(). (Felipe)
+  . Fixed memory leak when calling the Finfo constructor twice. (Felipe)
 
 - Intl:
   . Fixed bug #60192 (SegFault when Collator not constructed
index 6a4b70f25bf2b622145386d4f74dba06eeb92434..7064be437f8847b220f54dd58e8013cdb911fb63 100644 (file)
@@ -290,6 +290,16 @@ PHP_FUNCTION(finfo_open)
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &options, &file, &file_len) == FAILURE) {
                RETURN_FALSE;
        }
+       
+       if (object) {
+               struct finfo_object *finfo_obj = (struct finfo_object*)zend_object_store_get_object(object TSRMLS_CC);
+               
+               if (finfo_obj->ptr) {
+                       magic_close(finfo_obj->ptr->magic);
+                       efree(finfo_obj->ptr);
+                       finfo_obj->ptr = NULL;
+               }
+       }
 
        if (file_len == 0) {
                file = NULL;
diff --git a/ext/fileinfo/tests/finfo_open_002.phpt b/ext/fileinfo/tests/finfo_open_002.phpt
new file mode 100644 (file)
index 0000000..cf4809f
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+FileInfo - Calling the constructor twice
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+$x = new finfo;
+$x->finfo();
+
+echo "done!\n";
+
+?>
+--EXPECTF--
+done!
+
+