php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52827
Patch curlopt_stderr_with_test revision 2010-09-13 18:49 UTC by cataphract@php.net
Patch curlopt_stderr revision 2010-09-13 14:56 UTC by cataphract@php.net

Patch curlopt_stderr_with_test for cURL related Bug #52827

Patch version 2010-09-13 18:49 UTC

Return to Bug #52827 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: cataphract@php.net

Index: interface.c
===================================================================
--- interface.c	(revision 303177)
+++ interface.c	(working copy)
@@ -1826,7 +1826,6 @@
 						}
 						zval_add_ref(zvalue);
 						ch->handlers->std_err = *zvalue;
-						zend_list_addref(Z_LVAL_PP(zvalue));
 					} else {
 						php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
 						RETVAL_FALSE;
Index: tests/bug52827.phpt
===================================================================
--- tests/bug52827.phpt	(revision 0)
+++ tests/bug52827.phpt	(revision 0)
@@ -0,0 +1,32 @@
+--TEST--
+Bug #52827 (curl_setopt with CURLOPT_STDERR erroneously increments the resource refcount)
+--SKIPIF--
+<?php
+
+if (!extension_loaded('curl')) {
+	exit("skip curl extension not loaded");
+}
+
+?>
+--FILE--
+<?php
+$s = fopen('php://temp/maxmemory=1024','wb+');
+
+/* force conversion of inner stream to STDIO.
+ * This is not necessary in Windows because the
+ * cast to a FILE* handle in curl_setopt already
+ * forces the conversion in that platform. The
+ * reason for this conversion is that the memory
+ * stream has an ugly but working mechanism to
+ * prevent being double freed when it's encapsulated,
+ * while STDIO streams don't. */
+$i = 0;
+while ($i++ < 5000) {
+fwrite($s, str_repeat('a',1024));
+}
+$handle=curl_init('http://www.example.com');
+curl_setopt($handle, CURLOPT_STDERR, $s);
+
+echo "Done.";
+--EXPECTF--
+Done.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC