From b6137f4cb10bcf0a86a743077363375a01dfd6a5 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 23 Nov 2011 01:20:49 +0000 Subject: [PATCH] - Fixed memory leak when calling the Finfo constructor twice --- NEWS | 1 + ext/fileinfo/fileinfo.c | 10 ++++++++++ ext/fileinfo/tests/finfo_open_002.phpt | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 ext/fileinfo/tests/finfo_open_002.phpt diff --git a/NEWS b/NEWS index 9402ccdf54a..384796735ea 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 6a4b70f25bf..7064be437f8 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 00000000000..cf4809f0932 --- /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! + +