felipe Wed, 23 Nov 2011 01:20:49 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=319705
Log:
- Fixed memory leak when calling the Finfo constructor twice
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c
A php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_open_002.phpt
U php/php-src/branches/PHP_5_4/NEWS
U php/php-src/branches/PHP_5_4/ext/fileinfo/fileinfo.c
A php/php-src/branches/PHP_5_4/ext/fileinfo/tests/finfo_open_002.phpt
U php/php-src/trunk/ext/fileinfo/fileinfo.c
A php/php-src/trunk/ext/fileinfo/tests/finfo_open_002.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-11-22 22:11:15 UTC (rev 319704)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-11-23 01:20:49 UTC (rev 319705)
@@ -30,6 +30,7 @@
- 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
Modified: php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c 2011-11-22
22:11:15 UTC (rev 319704)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c 2011-11-23
01:20:49 UTC (rev 319705)
@@ -290,6 +290,16 @@
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;
Added: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_open_002.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_open_002.phpt
(rev 0)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_open_002.phpt
2011-11-23 01:20:49 UTC (rev 319705)
@@ -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!
+
+
Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS 2011-11-22 22:11:15 UTC (rev 319704)
+++ php/php-src/branches/PHP_5_4/NEWS 2011-11-23 01:20:49 UTC (rev 319705)
@@ -33,6 +33,7 @@
- Fileinfo:
. Fixed possible memory leak in finfo_open(). (Felipe)
+ . Fixed memory leak when calling the Finfo constructor twice. (Felipe)
- Intl:
. Fixed memory leak in several Intl locale functions. (Felipe)
Modified: php/php-src/branches/PHP_5_4/ext/fileinfo/fileinfo.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/fileinfo/fileinfo.c 2011-11-22
22:11:15 UTC (rev 319704)
+++ php/php-src/branches/PHP_5_4/ext/fileinfo/fileinfo.c 2011-11-23
01:20:49 UTC (rev 319705)
@@ -289,6 +289,16 @@
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lp", &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;
Added: php/php-src/branches/PHP_5_4/ext/fileinfo/tests/finfo_open_002.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/fileinfo/tests/finfo_open_002.phpt
(rev 0)
+++ php/php-src/branches/PHP_5_4/ext/fileinfo/tests/finfo_open_002.phpt
2011-11-23 01:20:49 UTC (rev 319705)
@@ -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!
+
+
Modified: php/php-src/trunk/ext/fileinfo/fileinfo.c
===================================================================
--- php/php-src/trunk/ext/fileinfo/fileinfo.c 2011-11-22 22:11:15 UTC (rev
319704)
+++ php/php-src/trunk/ext/fileinfo/fileinfo.c 2011-11-23 01:20:49 UTC (rev
319705)
@@ -289,6 +289,16 @@
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lp", &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;
Added: php/php-src/trunk/ext/fileinfo/tests/finfo_open_002.phpt
===================================================================
--- php/php-src/trunk/ext/fileinfo/tests/finfo_open_002.phpt
(rev 0)
+++ php/php-src/trunk/ext/fileinfo/tests/finfo_open_002.phpt 2011-11-23
01:20:49 UTC (rev 319705)
@@ -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!
+
+
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php