]> granicus.if.org Git - php/commitdiff
Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after fclose).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 30 Sep 2009 02:34:17 +0000 (02:34 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 30 Sep 2009 02:34:17 +0000 (02:34 +0000)
NEWS
ext/curl/interface.c
ext/curl/php_curl.h

diff --git a/NEWS b/NEWS
index 0295fa30a94dd6e82f58770645d7938d9a99f9c9..61701bac221f8771ee8a37d74fbce81b7742f542 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@
   mbstring.strict_mode is turned on). (Moriyoshi)
 - Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE
   cannot be set"). (Felipe)
+- Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after
+  fclose). (Ilia)
 - Fixed bug #49354 (mb_strcut() cuts wrong length when offset is in the middle
   of a multibyte character). (Moriyoshi)
 - Fixed bug #49528 (UTF-16 strings prefixed by BOMs wrondly converted).
index f5b4c51de843f1ec4838e93ac7078bf7175c3cd9..eb24646575817fc4e95d86a99eb2dc0befc1e069 100644 (file)
@@ -1228,10 +1228,22 @@ PHP_FUNCTION(curl_copy_handle)
 
        dupch->cp = cp;
        dupch->uses = 0;
+       if (ch->handlers->write->stream) {
+               Z_ADDREF_P(dupch->handlers->write->stream);
+               dupch->handlers->write->stream = ch->handlers->write->stream;
+       }
        dupch->handlers->write->method = ch->handlers->write->method;
        dupch->handlers->write->type   = ch->handlers->write->type;
+       if (ch->handlers->read->stream) {
+               Z_ADDREF_P(ch->handlers->read->stream);
+       }
+       dupch->handlers->read->stream  = ch->handlers->read->stream;
        dupch->handlers->read->method  = ch->handlers->read->method;
        dupch->handlers->write_header->method = ch->handlers->write_header->method;
+       if (ch->handlers->write_header->stream) {
+               Z_ADDREF_P(ch->handlers->write_header->stream);
+       }
+       dupch->handlers->write_header->stream = ch->handlers->write_header->stream;
 
        dupch->handlers->write->fp = ch->handlers->write->fp;
        dupch->handlers->write_header->fp = ch->handlers->write_header->fp;
@@ -1457,9 +1469,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
                        switch (option) {
                                case CURLOPT_FILE:
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
-                                               zend_list_addref(Z_LVAL_PP(zvalue));
+                                               Z_ADDREF_PP(zvalue);
                                                ch->handlers->write->fp = fp;
                                                ch->handlers->write->method = PHP_CURL_FILE;
+                                               ch->handlers->write->stream = *zvalue;
                                        } else {
                                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
                                                RETVAL_FALSE;
@@ -1468,9 +1481,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
                                        break;
                                case CURLOPT_WRITEHEADER:
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
-                                               zend_list_addref(Z_LVAL_PP(zvalue));
+                                               Z_ADDREF_PP(zvalue);
                                                ch->handlers->write_header->fp = fp;
                                                ch->handlers->write_header->method = PHP_CURL_FILE;
+                                               ch->handlers->write_header->stream = *zvalue;
                                        } else {
                                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
                                                RETVAL_FALSE;
@@ -1478,9 +1492,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
                                        }
                                        break;
                                case CURLOPT_INFILE:
-                                       zend_list_addref(Z_LVAL_PP(zvalue));
+                                       Z_ADDREF_PP(zvalue);
                                        ch->handlers->read->fp = fp;
                                        ch->handlers->read->fd = Z_LVAL_PP(zvalue);
+                                       ch->handlers->read->stream = *zvalue;
                                        break;
                                case CURLOPT_STDERR:
                                        if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
@@ -2129,6 +2144,16 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
                efree(ch->header.str);
        }
 
+       if (ch->handlers->write_header->stream) {
+               zval_ptr_dtor(&ch->handlers->write_header->stream);
+       }
+       if (ch->handlers->write->stream) {
+               zval_ptr_dtor(&ch->handlers->write->stream);
+       }
+       if (ch->handlers->read->stream) {
+               zval_ptr_dtor(&ch->handlers->read->stream);
+       }
+
        efree(ch->handlers->write);
        efree(ch->handlers->write_header);
        efree(ch->handlers->read);
index e3675c64ba9e3b3202a0dd7b25b35af35dec8f50..d43edca969029ddb7b7a58ad1dcdb67b9e55fcfc 100644 (file)
@@ -86,6 +86,7 @@ typedef struct {
        smart_str       buf;
        int             method;
        int             type;
+       zval            *stream;
 } php_curl_write;
 
 typedef struct {
@@ -94,6 +95,7 @@ typedef struct {
        FILE            *fp;
        long            fd;
        int             method;
+       zval            *stream;
 } php_curl_read;
 
 typedef struct {