1
0
mirror of https://github.com/php/php-src.git synced 2026-03-28 02:02:32 +01:00

MFH: Fixed #46164 (stream_filter_remove() closes the stream)

This commit is contained in:
Arnaud Le Blanc
2008-10-05 01:40:19 +00:00
parent e1443682af
commit 8ad19e1801
3 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
--TEST--
Bug #46164 - 1 (stream_filter_remove() closes the stream)
--FILE--
<?php
class user_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
stream_filter_register('user_filter','user_filter');
$fd = fopen('php://memory','w');
$filter = stream_filter_append($fd, 'user_filter');
stream_filter_remove($filter);
var_dump(fclose($fd));
?>
--EXPECT--
bool(true)

View File

@@ -0,0 +1,24 @@
--TEST--
Bug #46164 - 2 (stream_filter_remove() closes the stream)
--FILE--
<?php
class user_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
unset($this->stream);
return PSFS_PASS_ON;
}
}
stream_filter_register('user_filter','user_filter');
$fd = fopen('php://memory','w');
$filter = stream_filter_append($fd, 'user_filter');
fwrite($fd, "foo");
fflush($fd);
var_dump(fclose($fd));
?>
--EXPECT--
bool(true)

View File

@@ -180,12 +180,14 @@ php_stream_filter_status_t userfilter_filter(
zval *retval = NULL;
zval **args[4];
zval *zclosing, *zconsumed, *zin, *zout, *zstream;
zval zpropname;
int call_result;
if (FAILURE == zend_hash_find(Z_OBJPROP_P(obj), "stream", sizeof("stream"), (void**)&zstream)) {
/* Give the userfilter class a hook back to the stream */
ALLOC_INIT_ZVAL(zstream);
php_stream_to_zval(stream, zstream);
zval_copy_ctor(zstream);
add_property_zval(obj, "stream", zstream);
/* add_property_zval increments the refcount which is unwanted here */
zval_ptr_dtor(&zstream);
@@ -247,6 +249,13 @@ php_stream_filter_status_t userfilter_filter(
}
}
/* filter resources are cleaned up by the stream destructor,
* keeping a reference to the stream resource here would prevent it
* from being destroyed properly */
INIT_ZVAL(zpropname);
ZVAL_STRINGL(&zpropname, "stream", sizeof("stream")-1, 0);
Z_OBJ_HANDLER_P(obj, unset_property)(obj, &zpropname TSRMLS_CC);
zval_ptr_dtor(&zclosing);
zval_ptr_dtor(&zconsumed);
zval_ptr_dtor(&zout);