Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after fclose).

This commit is contained in:
Ilia Alshanetsky 2009-09-30 02:34:17 +00:00
parent e56e60c3a0
commit 809dbcda08
3 changed files with 32 additions and 4 deletions

3
NEWS
View file

@ -17,7 +17,8 @@
- Fixed bug #49630 (imap_listscan function missing). (Felipe) - Fixed bug #49630 (imap_listscan function missing). (Felipe)
- Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE - Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE
cannot be set"). (Felipe) cannot be set"). (Felipe)
- Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after
fclose). (Ilia)
?? ??? 2009, PHP 5.3.1RC? <- WHY IS THIS HERE? Gonna be released after 5.3.1 or what?? ?? ??? 2009, PHP 5.3.1RC? <- WHY IS THIS HERE? Gonna be released after 5.3.1 or what??
- Upgraded bundled sqlite to version 3.6.18. (Ilia) - Upgraded bundled sqlite to version 3.6.18. (Ilia)

View file

@ -1509,10 +1509,22 @@ PHP_FUNCTION(curl_copy_handle)
dupch->cp = cp; dupch->cp = cp;
dupch->uses = 0; 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->method = ch->handlers->write->method;
dupch->handlers->write->type = ch->handlers->write->type; 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->read->method = ch->handlers->read->method;
dupch->handlers->write_header->method = ch->handlers->write_header->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->fp = ch->handlers->write->fp;
dupch->handlers->write_header->fp = ch->handlers->write_header->fp; dupch->handlers->write_header->fp = ch->handlers->write_header->fp;
@ -1767,9 +1779,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
switch (option) { switch (option) {
case CURLOPT_FILE: case CURLOPT_FILE:
if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { 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->fp = fp;
ch->handlers->write->method = PHP_CURL_FILE; ch->handlers->write->method = PHP_CURL_FILE;
ch->handlers->write->stream = *zvalue;
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
RETVAL_FALSE; RETVAL_FALSE;
@ -1778,9 +1791,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
break; break;
case CURLOPT_WRITEHEADER: case CURLOPT_WRITEHEADER:
if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { 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->fp = fp;
ch->handlers->write_header->method = PHP_CURL_FILE; ch->handlers->write_header->method = PHP_CURL_FILE;
ch->handlers->write_header->stream = *zvalue;
} else { } else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
RETVAL_FALSE; RETVAL_FALSE;
@ -1788,9 +1802,10 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
} }
break; break;
case CURLOPT_INFILE: case CURLOPT_INFILE:
zend_list_addref(Z_LVAL_PP(zvalue)); Z_ADDREF_PP(zvalue);
ch->handlers->read->fp = fp; ch->handlers->read->fp = fp;
ch->handlers->read->fd = Z_LVAL_PP(zvalue); ch->handlers->read->fd = Z_LVAL_PP(zvalue);
ch->handlers->read->stream = *zvalue;
break; break;
case CURLOPT_STDERR: case CURLOPT_STDERR:
if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') { if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
@ -2477,6 +2492,16 @@ static void _php_curl_close_ex(php_curl *ch TSRMLS_DC)
efree(ch->header.str); 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);
efree(ch->handlers->write_header); efree(ch->handlers->write_header);
efree(ch->handlers->read); efree(ch->handlers->read);

View file

@ -86,6 +86,7 @@ typedef struct {
smart_str buf; smart_str buf;
int method; int method;
int type; int type;
zval *stream;
} php_curl_write; } php_curl_write;
typedef struct { typedef struct {
@ -94,6 +95,7 @@ typedef struct {
FILE *fp; FILE *fp;
long fd; long fd;
int method; int method;
zval *stream;
} php_curl_read; } php_curl_read;
typedef struct { typedef struct {