From: Felipe Pena Date: Wed, 23 Nov 2011 01:20:49 +0000 (+0000) Subject: - Fixed memory leak when calling the Finfo constructor twice X-Git-Tag: php-5.3.9RC2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6137f4cb10bcf0a86a743077363375a01dfd6a5;p=php - Fixed memory leak when calling the Finfo constructor twice --- diff --git a/NEWS b/NEWS index 9402ccdf54..384796735e 100644 --- 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 diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 6a4b70f25b..7064be437f 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -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 index 0000000000..cf4809f093 --- /dev/null +++ b/ext/fileinfo/tests/finfo_open_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +FileInfo - Calling the constructor twice +--SKIPIF-- + +--FILE-- +finfo(); + +echo "done!\n"; + +?> +--EXPECTF-- +done! + +