Index: ext/curl/interface.c =================================================================== RCS file: /repository/php-src/ext/curl/interface.c,v retrieving revision 1.62.2.14.2.27.2.49 diff -u -r1.62.2.14.2.27.2.49 interface.c --- ext/curl/interface.c 21 May 2009 12:52:05 -0000 1.62.2.14.2.27.2.49 +++ ext/curl/interface.c 26 May 2009 12:27:19 -0000 @@ -1673,6 +1673,20 @@ ch->handlers->read->fp = fp; ch->handlers->read->fd = Z_LVAL_PP(zvalue); break; + case CURLOPT_STDERR: + if (((php_stream *) what)->mode[0] != 'r') { + if (ch->handlers->stderr) { + zval_ptr_dtor(&ch->handlers->stderr); + } + zval_add_ref(zvalue); + ch->handlers->stderr = *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; + return 1; + } + /* break omitted intentionally */ default: error = curl_easy_setopt(ch->cp, option, fp); break; @@ -2268,6 +2282,11 @@ fprintf(stderr, "DTOR CALLED, ch = %x\n", ch); #endif + /* Prevent crash inside cURL if passed file has already been closed */ + if (ch->handlers->stderr && Z_REFCOUNT_P(ch->handlers->stderr) <= 0) { + curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr); + } + curl_easy_cleanup(ch->cp); #if LIBCURL_VERSION_NUM < 0x071101 zend_llist_clean(&ch->to_free.str); @@ -2293,6 +2312,9 @@ if (ch->handlers->passwd) { zval_ptr_dtor(&ch->handlers->passwd); } + if (ch->handlers->stderr) { + zval_ptr_dtor(&ch->handlers->stderr); + } if (ch->header.str_len > 0) { efree(ch->header.str); } Index: ext/curl/php_curl.h =================================================================== RCS file: /repository/php-src/ext/curl/php_curl.h,v retrieving revision 1.44.2.2.2.2.2.4 diff -u -r1.44.2.2.2.2.2.4 php_curl.h --- ext/curl/php_curl.h 3 May 2009 14:59:46 -0000 1.44.2.2.2.2.2.4 +++ ext/curl/php_curl.h 26 May 2009 12:27:19 -0000 @@ -108,6 +108,7 @@ php_curl_read *read; zval *passwd; php_curl_progress *progress; + zval *stderr; } php_curl_handlers; struct _php_curl_error {