Skip to content

Commit 809dbcd

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after fclose).
1 parent e56e60c commit 809dbcd

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

NEWS

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
- Fixed bug #49630 (imap_listscan function missing). (Felipe)
1818
- Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE
1919
cannot be set"). (Felipe)
20-
20+
- Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being deleted after
21+
fclose). (Ilia)
2122

2223
?? ??? 2009, PHP 5.3.1RC? <- WHY IS THIS HERE? Gonna be released after 5.3.1 or what??
2324
- Upgraded bundled sqlite to version 3.6.18. (Ilia)

ext/curl/interface.c

+28-3
Original file line numberDiff line numberDiff line change
@@ -1509,10 +1509,22 @@ PHP_FUNCTION(curl_copy_handle)
15091509

15101510
dupch->cp = cp;
15111511
dupch->uses = 0;
1512+
if (ch->handlers->write->stream) {
1513+
Z_ADDREF_P(dupch->handlers->write->stream);
1514+
dupch->handlers->write->stream = ch->handlers->write->stream;
1515+
}
15121516
dupch->handlers->write->method = ch->handlers->write->method;
15131517
dupch->handlers->write->type = ch->handlers->write->type;
1518+
if (ch->handlers->read->stream) {
1519+
Z_ADDREF_P(ch->handlers->read->stream);
1520+
}
1521+
dupch->handlers->read->stream = ch->handlers->read->stream;
15141522
dupch->handlers->read->method = ch->handlers->read->method;
15151523
dupch->handlers->write_header->method = ch->handlers->write_header->method;
1524+
if (ch->handlers->write_header->stream) {
1525+
Z_ADDREF_P(ch->handlers->write_header->stream);
1526+
}
1527+
dupch->handlers->write_header->stream = ch->handlers->write_header->stream;
15161528

15171529
dupch->handlers->write->fp = ch->handlers->write->fp;
15181530
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
17671779
switch (option) {
17681780
case CURLOPT_FILE:
17691781
if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1770-
zend_list_addref(Z_LVAL_PP(zvalue));
1782+
Z_ADDREF_PP(zvalue);
17711783
ch->handlers->write->fp = fp;
17721784
ch->handlers->write->method = PHP_CURL_FILE;
1785+
ch->handlers->write->stream = *zvalue;
17731786
} else {
17741787
php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
17751788
RETVAL_FALSE;
@@ -1778,19 +1791,21 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
17781791
break;
17791792
case CURLOPT_WRITEHEADER:
17801793
if (((php_stream *) what)->mode[0] != 'r' || ((php_stream *) what)->mode[1] == '+') {
1781-
zend_list_addref(Z_LVAL_PP(zvalue));
1794+
Z_ADDREF_PP(zvalue);
17821795
ch->handlers->write_header->fp = fp;
17831796
ch->handlers->write_header->method = PHP_CURL_FILE;
1797+
ch->handlers->write_header->stream = *zvalue;
17841798
} else {
17851799
php_error_docref(NULL TSRMLS_CC, E_WARNING, "the provided file handle is not writable");
17861800
RETVAL_FALSE;
17871801
return 1;
17881802
}
17891803
break;
17901804
case CURLOPT_INFILE:
1791-
zend_list_addref(Z_LVAL_PP(zvalue));
1805+
Z_ADDREF_PP(zvalue);
17921806
ch->handlers->read->fp = fp;
17931807
ch->handlers->read->fd = Z_LVAL_PP(zvalue);
1808+
ch->handlers->read->stream = *zvalue;
17941809
break;
17951810
case CURLOPT_STDERR:
17961811
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)
24772492
efree(ch->header.str);
24782493
}
24792494

2495+
if (ch->handlers->write_header->stream) {
2496+
zval_ptr_dtor(&ch->handlers->write_header->stream);
2497+
}
2498+
if (ch->handlers->write->stream) {
2499+
zval_ptr_dtor(&ch->handlers->write->stream);
2500+
}
2501+
if (ch->handlers->read->stream) {
2502+
zval_ptr_dtor(&ch->handlers->read->stream);
2503+
}
2504+
24802505
efree(ch->handlers->write);
24812506
efree(ch->handlers->write_header);
24822507
efree(ch->handlers->read);

ext/curl/php_curl.h

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ typedef struct {
8686
smart_str buf;
8787
int method;
8888
int type;
89+
zval *stream;
8990
} php_curl_write;
9091

9192
typedef struct {
@@ -94,6 +95,7 @@ typedef struct {
9495
FILE *fp;
9596
long fd;
9697
int method;
98+
zval *stream;
9799
} php_curl_read;
98100

99101
typedef struct {

0 commit comments

Comments
 (0)