lbarnaud Thu Jan 8 18:40:56 2009 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/standard user_filters.c
/php-src/ext/standard/tests/filters filter_errors.inc
filter_errors_convert_base64_decode.phpt
filter_errors_user.phpt
Log:
MFH:
Fix memleak when a user filter appends a bucket and returns != PSFS_PASS_ON
Improved tests
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/user_filters.c?r1=1.31.2.4.2.12&r2=1.31.2.4.2.13&diff_format=u
Index: php-src/ext/standard/user_filters.c
diff -u php-src/ext/standard/user_filters.c:1.31.2.4.2.12
php-src/ext/standard/user_filters.c:1.31.2.4.2.13
--- php-src/ext/standard/user_filters.c:1.31.2.4.2.12 Wed Dec 31 11:17:46 2008
+++ php-src/ext/standard/user_filters.c Thu Jan 8 18:40:56 2009
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: user_filters.c,v 1.31.2.4.2.12 2008/12/31 11:17:46 sebastian Exp $ */
+/* $Id: user_filters.c,v 1.31.2.4.2.13 2009/01/08 18:40:56 lbarnaud Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -248,6 +248,14 @@
php_stream_bucket_delref(bucket TSRMLS_CC);
}
}
+ if (ret != PSFS_PASS_ON) {
+ php_stream_bucket *bucket = buckets_out->head;
+ while (bucket != NULL) {
+ php_stream_bucket_unlink(bucket TSRMLS_CC);
+ php_stream_bucket_delref(bucket TSRMLS_CC);
+ bucket = buckets_out->head;
+ }
+ }
/* filter resources are cleaned up by the stream destructor,
* keeping a reference to the stream resource here would prevent it
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors.inc?r1=1.1.4.2&r2=1.1.4.3&diff_format=u
Index: php-src/ext/standard/tests/filters/filter_errors.inc
diff -u php-src/ext/standard/tests/filters/filter_errors.inc:1.1.4.2
php-src/ext/standard/tests/filters/filter_errors.inc:1.1.4.3
--- php-src/ext/standard/tests/filters/filter_errors.inc:1.1.4.2 Thu Jan
8 17:03:42 2009
+++ php-src/ext/standard/tests/filters/filter_errors.inc Thu Jan 8
18:40:56 2009
@@ -27,7 +27,7 @@
fwrite($stream, b"$data");
fseek($stream, 0, SEEK_SET);
- stream_get_line($stream, 8192, "\r\n");
+ stream_filter_append($stream, $filter);
stream_get_contents($stream);
}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u
Index:
php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt
diff -u
php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.1.4.2
php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.1.4.3
---
php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt:1.1.4.2
Thu Jan 8 17:03:42 2009
+++ php-src/ext/standard/tests/filters/filter_errors_convert_base64_decode.phpt
Thu Jan 8 18:40:56 2009
@@ -14,3 +14,5 @@
Warning: stream_filter_append(): Filter failed to process pre-buffered data in
%s
test filtering of non buffered data
+
+Warning: stream_get_contents(): stream filter (convert.base64-decode): invalid
byte sequence in %s
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/filters/filter_errors_user.phpt?r1=1.1.4.2&r2=1.1.4.3&diff_format=u
Index: php-src/ext/standard/tests/filters/filter_errors_user.phpt
diff -u php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.1.4.2
php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.1.4.3
--- php-src/ext/standard/tests/filters/filter_errors_user.phpt:1.1.4.2 Thu Jan
8 17:03:42 2009
+++ php-src/ext/standard/tests/filters/filter_errors_user.phpt Thu Jan 8
18:40:56 2009
@@ -26,14 +26,18 @@
}
class test_filter3 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
- $bucket = stream_bucket_new($this->stream, "42");
- stream_bucket_append($out, $bucket);
+ if (!$closing) {
+ $bucket = stream_bucket_new($this->stream, "42");
+ stream_bucket_append($out, $bucket);
+ }
return PSFS_ERR_FATAL;
}
}
class test_filter4 extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
- $bucket = stream_bucket_new($this->stream, "42");
+ if (!$closing) {
+ $bucket = stream_bucket_new($this->stream, "42");
+ }
return PSFS_ERR_FATAL;
}
}
@@ -44,6 +48,43 @@
filter_errors_test("test_filter$i", "42");
}
+echo "test append / read / remove\n";
+for($i = 0; $i < 5; ++$i) {
+ echo "test_filter$i\n";
+ $stream = fopen('php://memory', 'wb+');
+ fwrite($stream, b"42");
+ fseek($stream, 0, SEEK_SET);
+ $f = stream_filter_append($stream, "test_filter$i");
+ stream_get_contents($stream);
+ stream_filter_remove($f);
+}
+
+echo "test append all / read / remove all\n";
+$stream = fopen('php://memory', 'wb+');
+fwrite($stream, b"42");
+fseek($stream, 0, SEEK_SET);
+$filters = array();
+for($i = 0; $i < 5; ++$i) {
+ echo "test_filter$i\n";
+ $filters[] = stream_filter_append($stream, "test_filter$i");
+}
+stream_get_contents($stream);
+foreach($filters as $filter) {
+ stream_filter_remove($filter);
+}
+
+echo "test append all / read / close\n";
+$stream = fopen('php://memory', 'wb+');
+fwrite($stream, b"42");
+fseek($stream, 0, SEEK_SET);
+$filters = array();
+for($i = 0; $i < 5; ++$i) {
+ echo "test_filter$i\n";
+ $filters[] = stream_filter_append($stream, "test_filter$i");
+}
+stream_get_contents($stream);
+fclose($stream);
+
?>
--EXPECTF--
test_filter0
@@ -54,6 +95,8 @@
Warning: stream_filter_append(): Filter failed to process pre-buffered data in
%s
test filtering of non buffered data
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
test_filter1
bool(true)
test filtering of buffered data
@@ -74,6 +117,8 @@
Warning: stream_filter_append(): Filter failed to process pre-buffered data in
%s
test filtering of non buffered data
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
test_filter4
bool(true)
test filtering of buffered data
@@ -82,3 +127,53 @@
Warning: stream_filter_append(): Filter failed to process pre-buffered data in
%s
test filtering of non buffered data
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
+test append / read / remove
+test_filter0
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test_filter1
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test_filter2
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test_filter3
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test_filter4
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test append all / read / remove all
+test_filter0
+test_filter1
+test_filter2
+test_filter3
+test_filter4
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+
+Warning: stream_filter_remove(): Unable to flush filter, not removing in %s
+test append all / read / close
+test_filter0
+test_filter1
+test_filter2
+test_filter3
+test_filter4
+
+Warning: stream_get_contents(): Unprocessed filter buckets remaining on input
brigade in %s
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php