pierrick                                 Mon, 21 Nov 2011 02:29:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=319593

Log:
Fix memory leak

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/curl/interface.c
    U   php/php-src/branches/PHP_5_4/ext/curl/interface.c
    U   php/php-src/trunk/ext/curl/interface.c

Modified: php/php-src/branches/PHP_5_3/ext/curl/interface.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/curl/interface.c   2011-11-21 02:10:57 UTC 
(rev 319592)
+++ php/php-src/branches/PHP_5_3/ext/curl/interface.c   2011-11-21 02:29:24 UTC 
(rev 319593)
@@ -1422,6 +1422,9 @@
        (*ch)->header.str_len = 0;

        memset(&(*ch)->err, 0, sizeof((*ch)->err));
+       (*ch)->handlers->write->stream = NULL;
+       (*ch)->handlers->write_header->stream = NULL;
+       (*ch)->handlers->read->stream = NULL;

        zend_llist_init(&(*ch)->to_free.str,   sizeof(char *),            
(llist_dtor_func_t) curl_free_string, 0);
        zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist), 
(llist_dtor_func_t) curl_free_slist,  0);
@@ -1890,6 +1893,9 @@
                        switch (option) {
                                case CURLOPT_FILE:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write->fp = fp;
                                                ch->handlers->write->method = 
PHP_CURL_FILE;
@@ -1902,6 +1908,9 @@
                                        break;
                                case CURLOPT_WRITEHEADER:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write_header->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write_header->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write_header->fp 
= fp;
                                                
ch->handlers->write_header->method = PHP_CURL_FILE;
@@ -1913,6 +1922,9 @@
                                        }
                                        break;
                                case CURLOPT_INFILE:
+                                       if (ch->handlers->read->stream) {
+                                               
Z_DELREF_P(ch->handlers->read->stream);
+                                       }
                                        Z_ADDREF_PP(zvalue);
                                        ch->handlers->read->fp = fp;
                                        ch->handlers->read->fd = 
Z_LVAL_PP(zvalue);

Modified: php/php-src/branches/PHP_5_4/ext/curl/interface.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/curl/interface.c   2011-11-21 02:10:57 UTC 
(rev 319592)
+++ php/php-src/branches/PHP_5_4/ext/curl/interface.c   2011-11-21 02:29:24 UTC 
(rev 319593)
@@ -1420,6 +1420,9 @@
        (*ch)->header.str_len = 0;

        memset(&(*ch)->err, 0, sizeof((*ch)->err));
+       (*ch)->handlers->write->stream = NULL;
+       (*ch)->handlers->write_header->stream = NULL;
+       (*ch)->handlers->read->stream = NULL;

        zend_llist_init(&(*ch)->to_free.str,   sizeof(char *),            
(llist_dtor_func_t) curl_free_string, 0);
        zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist), 
(llist_dtor_func_t) curl_free_slist,  0);
@@ -1886,6 +1889,9 @@
                        switch (option) {
                                case CURLOPT_FILE:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write->fp = fp;
                                                ch->handlers->write->method = 
PHP_CURL_FILE;
@@ -1898,6 +1904,9 @@
                                        break;
                                case CURLOPT_WRITEHEADER:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write_header->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write_header->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write_header->fp 
= fp;
                                                
ch->handlers->write_header->method = PHP_CURL_FILE;
@@ -1909,6 +1918,9 @@
                                        }
                                        break;
                                case CURLOPT_INFILE:
+                                       if (ch->handlers->read->stream) {
+                                               
Z_DELREF_P(ch->handlers->read->stream);
+                                       }
                                        Z_ADDREF_PP(zvalue);
                                        ch->handlers->read->fp = fp;
                                        ch->handlers->read->fd = 
Z_LVAL_PP(zvalue);

Modified: php/php-src/trunk/ext/curl/interface.c
===================================================================
--- php/php-src/trunk/ext/curl/interface.c      2011-11-21 02:10:57 UTC (rev 
319592)
+++ php/php-src/trunk/ext/curl/interface.c      2011-11-21 02:29:24 UTC (rev 
319593)
@@ -1420,6 +1420,9 @@
        (*ch)->header.str_len = 0;

        memset(&(*ch)->err, 0, sizeof((*ch)->err));
+       (*ch)->handlers->write->stream = NULL;
+       (*ch)->handlers->write_header->stream = NULL;
+       (*ch)->handlers->read->stream = NULL;

        zend_llist_init(&(*ch)->to_free.str,   sizeof(char *),            
(llist_dtor_func_t) curl_free_string, 0);
        zend_llist_init(&(*ch)->to_free.slist, sizeof(struct curl_slist), 
(llist_dtor_func_t) curl_free_slist,  0);
@@ -1886,6 +1889,9 @@
                        switch (option) {
                                case CURLOPT_FILE:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write->fp = fp;
                                                ch->handlers->write->method = 
PHP_CURL_FILE;
@@ -1898,6 +1904,9 @@
                                        break;
                                case CURLOPT_WRITEHEADER:
                                        if (((php_stream *) what)->mode[0] != 
'r' || ((php_stream *) what)->mode[1] == '+') {
+                                               if 
(ch->handlers->write_header->stream) {
+                                                       
Z_DELREF_P(ch->handlers->write_header->stream);
+                                               }
                                                Z_ADDREF_PP(zvalue);
                                                ch->handlers->write_header->fp 
= fp;
                                                
ch->handlers->write_header->method = PHP_CURL_FILE;
@@ -1909,6 +1918,9 @@
                                        }
                                        break;
                                case CURLOPT_INFILE:
+                                       if (ch->handlers->read->stream) {
+                                               
Z_DELREF_P(ch->handlers->read->stream);
+                                       }
                                        Z_ADDREF_PP(zvalue);
                                        ch->handlers->read->fp = fp;
                                        ch->handlers->read->fd = 
Z_LVAL_PP(zvalue);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to