From 2875d0f9204122901f90072263e23e21a857b8a2 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 12 Nov 2020 12:18:33 +0100 Subject: Fix memory leak when user filter onCreate returns false --- .../filters/php_user_filter_onCreate_failure.phpt | 24 ++++++++++++++++++++++ ext/standard/user_filters.c | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 ext/standard/tests/filters/php_user_filter_onCreate_failure.phpt diff --git a/ext/standard/tests/filters/php_user_filter_onCreate_failure.phpt b/ext/standard/tests/filters/php_user_filter_onCreate_failure.phpt new file mode 100644 index 0000000000..5b0c1d5d9c --- /dev/null +++ b/ext/standard/tests/filters/php_user_filter_onCreate_failure.phpt @@ -0,0 +1,24 @@ +--TEST-- +php_user_filter onCreate() returns false +--FILE-- + +--EXPECTF-- +Warning: stream_filter_append(): Unable to create or locate filter "my_filter" in %s on line %d +bool(false) +string(4) "Test" diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index b62e8a2d7c..758f79ff11 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -342,6 +342,8 @@ static php_stream_filter *user_filter_factory_create(const char *filtername, &retval, 0, NULL); + zval_ptr_dtor(&func_name); + if (Z_TYPE(retval) != IS_UNDEF) { if (Z_TYPE(retval) == IS_FALSE) { /* User reported filter creation error "return false;" */ @@ -359,7 +361,6 @@ static php_stream_filter *user_filter_factory_create(const char *filtername, } zval_ptr_dtor(&retval); } - zval_ptr_dtor(&func_name); /* set the filter property, this will be used during cleanup */ ZVAL_RES(&zfilter, zend_register_resource(filter, le_userfilters)); -- cgit v1.2.1