1--TEST--
2Bug #54350: Memory corruption with user_filter
3--FILE--
4<?php
5
6class user_filter extends php_user_filter {
7    function filter($in, $out, &$consumed, $closing): int {
8        while ($bucket = stream_bucket_make_writeable($in)) {
9        }
10        try {
11            fclose($this->stream);
12        } catch (TypeError $e) {
13            echo $e->getMessage(), "\n";
14        }
15        return 0;
16    }
17}
18stream_filter_register('user_filter','user_filter');
19$fd = fopen('php://memory','w');
20$filter = stream_filter_append($fd, 'user_filter');
21fwrite($fd, "foo");
22
23?>
24--EXPECTF--
25Warning: fclose(): 5 is not a valid stream resource in %s on line %d
26fclose(): supplied resource is not a valid stream resource
27