- no history logging by default
authorMichael Wallner <mike@php.net>
Wed, 26 Oct 2005 15:54:44 +0000 (15:54 +0000)
committerMichael Wallner <mike@php.net>
Wed, 26 Oct 2005 15:54:44 +0000 (15:54 +0000)
- fix occasional memleaks

http_encoding_api.c
http_request_object.c
http_response_object.c
php_http_api.h

index 18823e8950fbd584abfb92c03a987ed7f2b9f3e1..0062623fec3526d368d27cb61bdbbae41055369c 100644 (file)
@@ -84,8 +84,8 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco
                                                http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid character (expected 0x0A; got: 0x%02X)", *n_ptr);
                                        }
                                } else {
-                                       char *error = estrndup(n_ptr, strcspn(n_ptr, "\r\n "));
-                                       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid chunk size: '%s' at pos %d", error, n_ptr - encoded);
+                                       char *error = estrndup(e_ptr, strcspn(n_ptr, "\r\n "));
+                                       http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Invalid chunk size: '%s' at pos %ld of %lu", error, (long) (n_ptr - encoded), (unsigned long) encoded_len);
                                        efree(error);
                                }
                                return NULL;
index d32f858c3d40583f752503b7e5236ed72231f84e..cad4bd63783757342c18819336a1714b9edbc1ea 100644 (file)
@@ -374,7 +374,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        DCL_PROP(PROTECTED, string, queryData, "");
        DCL_PROP(PROTECTED, string, putFile, "");
 
-       DCL_PROP(PUBLIC, bool, recordHistory, 1);
+       DCL_PROP(PUBLIC, bool, recordHistory, 0);
 
 #ifndef WONKY
        /*
@@ -448,7 +448,7 @@ void _http_request_object_free(zend_object *object TSRMLS_DC)
 
 STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC)
 {
-       zval *meth, *URL;
+       zval *meth, *URL, *meth_p, *URL_p;
        char *request_uri;
        STATUS status = SUCCESS;
 
@@ -457,13 +457,19 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
        }
        HTTP_CHECK_CURL_INIT(obj->ch, curl_easy_init(), return FAILURE);
 
-       URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url));
+       URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url), &URL_p);
        // HTTP_URI_MAXLEN+1 long char *
        if (!(request_uri = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0))) {
+               if (URL_p) {
+                       zval_ptr_dtor(&URL_p);
+               }
                return FAILURE;
        }
+       if (URL_p) {
+               zval_ptr_dtor(&URL_p);
+       }
        
-       meth = convert_to_type_ex(IS_LONG, GET_PROP(obj, method));
+       meth = convert_to_type_ex(IS_LONG, GET_PROP(obj, method), &meth_p);
        switch (Z_LVAL_P(meth))
        {
                case HTTP_GET:
@@ -491,10 +497,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                default:
                {
                        /* check for raw post data */
-                       zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
+                       zval *raw_data_p, *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData), &raw_data_p);
                        
                        if (Z_STRLEN_P(raw_data)) {
-                               zval *ctype = convert_to_type_ex(IS_STRING, GET_PROP(obj, contentType));
+                               zval *ctype_p, *ctype = convert_to_type_ex(IS_STRING, GET_PROP(obj, contentType), &ctype_p);
                                
                                if (Z_STRLEN_P(ctype)) {
                                        zval **headers, *opts = GET_PROP(obj, options);
@@ -518,6 +524,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                                                add_assoc_zval(opts, "headers", headers);
                                        }
                                }
+
+                               if (ctype_p) {
+                                       zval_ptr_dtor(&ctype_p);
+                               }
                                
                                body->type = HTTP_REQUEST_BODY_CSTRING;
                                body->data = estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data));
@@ -525,12 +535,20 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        } else {
                                status = http_request_body_fill(body, Z_ARRVAL_P(GET_PROP(obj, postFields)), Z_ARRVAL_P(GET_PROP(obj, postFiles)));
                        }
+
+                       if (raw_data_p) {
+                               zval_ptr_dtor(&raw_data_p);
+                       }
                }
                break;
        }
+
+       if (meth_p) {
+               zval_ptr_dtor(&meth_p);
+       }
        
        if (status == SUCCESS) {
-               zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
+               zval *qdata_p, *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData), &qdata_p);
                
                if (Z_STRLEN_P(qdata)) {
                        if (!strchr(request_uri, '?')) {
@@ -541,6 +559,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_
                        strlcat(request_uri, Z_STRVAL_P(qdata), HTTP_URI_MAXLEN);
                }
                
+               if (qdata_p) {
+                       zval_ptr_dtor(&qdata_p);
+               }
+               
                status = http_request_init(obj->ch, Z_LVAL_P(meth), request_uri, body, Z_ARRVAL_P(GET_PROP(obj, options)));
        }
        efree(request_uri);
@@ -664,10 +686,10 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *opts, **options;
+               zval *opts_p, *opts, **options;
                getObject(http_request_object, obj);
 
-               opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options));
+               opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options), &opts_p);
 
                array_init(return_value);
 
@@ -675,6 +697,10 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS,
                        convert_to_array(*options);
                        array_copy(*options, return_value);
                }
+
+               if (opts_p) {
+                       zval_ptr_dtor(&opts_p);
+               }
        }
 }
 
@@ -835,12 +861,16 @@ PHP_METHOD(HttpRequest, getOptions)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *opts;
+               zval *opts_p, *opts;
                getObject(http_request_object, obj);
 
-               opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options));
+               opts = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, options), &opts_p);
                array_init(return_value);
                array_copy(opts, return_value);
+
+               if (opts_p) {
+                       zval_ptr_dtor(&opts_p);
+               }
        }
 }
 /* }}} */
@@ -1149,9 +1179,13 @@ PHP_METHOD(HttpRequest, getQueryData)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
+               zval *qdata_p, *qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData), &qdata_p);
                
                RETURN_ZVAL(qdata, 1, 0);
+
+               if (qdata_p) {
+                       zval_ptr_dtor(&qdata_p);
+               }
        }
 }
 /* }}} */
@@ -1167,7 +1201,7 @@ PHP_METHOD(HttpRequest, getQueryData)
  */
 PHP_METHOD(HttpRequest, addQueryData)
 {
-       zval *qdata, *old_qdata;
+       zval *qdata, *old_qdata, *old_qdata_p;
        char *query_data = NULL;
        size_t query_data_len = 0;
        getObject(http_request_object, obj);
@@ -1176,15 +1210,22 @@ PHP_METHOD(HttpRequest, addQueryData)
                RETURN_FALSE;
        }
 
-       old_qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData));
+       old_qdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, queryData), &old_qdata_p);
 
        if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) {
+               if (old_qdata_p) {
+                       zval_ptr_dtor(&old_qdata_p);
+               }
                RETURN_FALSE;
        }
 
        UPD_STRL(obj, queryData, query_data, query_data_len);
        efree(query_data);
 
+       if (old_qdata_p) {
+               zval_ptr_dtor(&old_qdata_p);
+       }
+
        RETURN_TRUE;
 }
 /* }}} */
@@ -1259,10 +1300,14 @@ PHP_METHOD(HttpRequest, getPostFields)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *post_data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFields));
+               zval *post_data_p, *post_data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFields), &post_data_p);
                
                array_init(return_value);
                array_copy(post_data, return_value);
+
+               if (post_data_p) {
+                       zval_ptr_dtor(&post_data_p);
+               }
        }
 }
 /* }}} */
@@ -1318,7 +1363,7 @@ PHP_METHOD(HttpRequest, addRawPostData)
        }
        
        if (data_len) {
-               zval *zdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
+               zval *zdata_p, *zdata = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData), &zdata_p);
                
                new_data = emalloc(Z_STRLEN_P(zdata) + data_len + 1);
                new_data[Z_STRLEN_P(zdata) + data_len] = '\0';
@@ -1329,6 +1374,10 @@ PHP_METHOD(HttpRequest, addRawPostData)
                
                memcpy(new_data + Z_STRLEN_P(zdata), raw_data, data_len);
                UPD_STRL(obj, rawPostData, new_data, Z_STRLEN_P(zdata) + data_len);
+
+               if (zdata_p) {
+                       zval_ptr_dtor(&zdata_p);
+               }
        }
        
        RETURN_TRUE;
@@ -1347,9 +1396,13 @@ PHP_METHOD(HttpRequest, getRawPostData)
        
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData));
+               zval *raw_data_p, *raw_data = convert_to_type_ex(IS_STRING, GET_PROP(obj, rawPostData), &raw_data_p);
                
-               RETURN_ZVAL(raw_data, 1, 0);
+               RETVAL_ZVAL(raw_data, 1, 0);
+
+               if (raw_data_p) {
+                       zval_ptr_dtor(&raw_data_p);
+               }
        }
 }
 /* }}} */
@@ -1444,10 +1497,14 @@ PHP_METHOD(HttpRequest, getPostFiles)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *files = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFiles));
+               zval *files_p, *files = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, postFiles), &files_p);
 
                array_init(return_value);
                array_copy(files, return_value);
+
+               if (files_p) {
+                       zval_ptr_dtor(&files_p);
+               }
        }
 }
 /* }}} */
@@ -1488,9 +1545,13 @@ PHP_METHOD(HttpRequest, getPutFile)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *putfile = convert_to_type_ex(IS_STRING, GET_PROP(obj, putFile));
+               zval *putfile_p, *putfile = convert_to_type_ex(IS_STRING, GET_PROP(obj, putFile), &putfile_p);
                
-               RETURN_ZVAL(putfile, 1, 0);
+               RETVAL_ZVAL(putfile, 1, 0);
+
+               if (putfile_p) {
+                       zval_ptr_dtor(&putfile_p);
+               }
        }
 }
 /* }}} */
@@ -1512,10 +1573,14 @@ PHP_METHOD(HttpRequest, getResponseData)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
+               zval *data_p, *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData), &data_p);
                
                array_init(return_value);
                array_copy(data, return_value);
+
+               if (data_p) {
+                       zval_ptr_dtor(&data_p);
+               }
        }
 }
 /* }}} */
@@ -1536,7 +1601,7 @@ PHP_METHOD(HttpRequest, getResponseData)
 PHP_METHOD(HttpRequest, getResponseHeader)
 {
        IF_RETVAL_USED {
-               zval *data, **headers, **header;
+               zval *data_p, *data, **headers, **header;
                char *header_name = NULL;
                int header_len = 0;
                getObject(http_request_object, obj);
@@ -1545,18 +1610,23 @@ PHP_METHOD(HttpRequest, getResponseHeader)
                        RETURN_FALSE;
                }
 
-               data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
-               if (SUCCESS != zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
-                       RETURN_FALSE;
-               }
-               convert_to_array_ex(headers);
-               if (!header_len || !header_name) {
-                       array_init(return_value);
-                       array_copy(*headers, return_value);
-               } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) {
-                       RETURN_ZVAL(*header, 1, 0);
+               data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData), &data_p);
+               if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
+                       convert_to_array(*headers);
+                       if (!header_len || !header_name) {
+                               array_init(return_value);
+                               array_copy(*headers, return_value);
+                       } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) {
+                               RETVAL_ZVAL(*header, 1, 0);
+                       } else {
+                               RETVAL_FALSE;
+                       }
                } else {
-                       RETURN_FALSE;
+                       RETVAL_FALSE;
+               }
+
+               if (data_p) {
+                       zval_ptr_dtor(&data_p);
                }
        }
 }
@@ -1591,7 +1661,7 @@ PHP_METHOD(HttpRequest, getResponseCookie)
 
                array_init(return_value);
 
-               data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
+               data = convert_to_type(IS_ARRAY, GET_PROP(obj, responseData));
                if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
                        ulong idx = 0;
                        char *key = NULL;
@@ -1681,10 +1751,9 @@ PHP_METHOD(HttpRequest, getResponseBody)
        IF_RETVAL_USED {
                zval **body;
                getObject(http_request_object, obj);
-               zval *data = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseData));
+               zval *data = convert_to_type(IS_ARRAY, GET_PROP(obj, responseData));
                
                if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body)) {
-                       convert_to_string_ex(body);
                        RETURN_ZVAL(*body, 1, 0);
                } else {
                        RETURN_FALSE;
@@ -1708,9 +1777,13 @@ PHP_METHOD(HttpRequest, getResponseCode)
 
        IF_RETVAL_USED {
                getObject(http_request_object, obj);
-               zval *code = convert_to_type_ex(IS_LONG, GET_PROP(obj, responseCode));
+               zval *code_p, *code = convert_to_type_ex(IS_LONG, GET_PROP(obj, responseCode), &code_p);
                
-               RETURN_ZVAL(code, 1, 0);
+               RETVAL_ZVAL(code, 1, 0);
+
+               if (code_p) {
+                       zval_ptr_dtor(&code_p);
+               }
        }
 }
 /* }}} */
@@ -1743,7 +1816,7 @@ PHP_METHOD(HttpRequest, getResponseInfo)
                        RETURN_FALSE;
                }
 
-               info = convert_to_type_ex(IS_ARRAY, GET_PROP(obj, responseInfo));
+               info = convert_to_type(IS_ARRAY, GET_PROP(obj, responseInfo));
 
                if (info_len && info_name) {
                        if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) {
index e255989e7fbcc21c4fb84b139cf0d0a4c7b4d218..915297ef86db87231419032765120263d178d687 100644 (file)
@@ -414,9 +414,13 @@ PHP_METHOD(HttpResponse, getCache)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *cache = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(cache));
+               zval *cache_p, *cache = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(cache), &cache_p);
                
-               RETURN_ZVAL(cache, 1, 0);
+               RETVAL_ZVAL(cache, 1, 0);
+
+               if (cache_p) {
+                       zval_ptr_dtor(&cache_p);
+               }
        }
 }
 /* }}}*/
@@ -452,9 +456,13 @@ PHP_METHOD(HttpResponse, getGzip)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *gzip = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(gzip));
+               zval *gzip_p, *gzip = convert_to_type_ex(IS_BOOL, GET_STATIC_PROP(gzip), &gzip_p);
                
-               RETURN_ZVAL(gzip, 1, 0);
+               RETVAL_ZVAL(gzip, 1, 0);
+
+               if (gzip_p) {
+                       zval_ptr_dtor(&gzip_p);
+               }
        }
 }
 /* }}} */
@@ -504,9 +512,13 @@ PHP_METHOD(HttpResponse, getCacheControl)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *ccontrol = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl));
+               zval *ccontrol_p, *ccontrol = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl), &ccontrol_p);
                
-               RETURN_ZVAL(ccontrol, 1, 0);
+               RETVAL_ZVAL(ccontrol, 1, 0);
+
+               if (ccontrol_p) {
+                       zval_ptr_dtor(&ccontrol_p);
+               }
        }
 }
 /* }}} */
@@ -547,9 +559,13 @@ PHP_METHOD(HttpResponse, getContentType)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType));
+               zval *ctype_p, *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType), &ctype_p);
                
-               RETURN_ZVAL(ctype, 1, 0);
+               RETVAL_ZVAL(ctype, 1, 0);
+
+               if (ctype_p) {
+                       zval_ptr_dtor(&ctype_p);
+               }
        }
 }
 /* }}} */
@@ -656,9 +672,13 @@ PHP_METHOD(HttpResponse, getContentDisposition)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *cd = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentDisposition));
+               zval *cd_p, *cd = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentDisposition), &cd_p);
                
-               RETURN_ZVAL(cd, 1, 0);
+               RETVAL_ZVAL(cd, 1, 0);
+
+               if (cd_p) {
+                       zval_ptr_dtor(&cd_p);
+               }
        }
 }
 /* }}} */
@@ -695,9 +715,13 @@ PHP_METHOD(HttpResponse, getETag)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag));
+               zval *etag_p, *etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag), &etag_p);
                
-               RETURN_ZVAL(etag, 1, 0);
+               RETVAL_ZVAL(etag, 1, 0);
+
+               if (etag_p) {
+                       zval_ptr_dtor(&etag_p);
+               }
        }
 }
 /* }}} */
@@ -734,9 +758,13 @@ PHP_METHOD(HttpResponse, getLastModified)
        NO_ARGS;
        
        IF_RETVAL_USED {
-               zval *lm = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified));
+               zval *lm_p, *lm = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified), &lm_p);
                
-               RETURN_ZVAL(lm, 1, 0);
+               RETVAL_ZVAL(lm, 1, 0);
+
+               if (lm_p) {
+                       zval_ptr_dtor(&lm_p);
+               }
        }
 }
 /* }}} */
@@ -777,9 +805,13 @@ PHP_METHOD(HttpResponse, getThrottleDelay)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *delay = convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay));
+               zval *delay_p, *delay = convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay), &delay_p);
                
-               RETURN_ZVAL(delay, 1, 0);
+               RETVAL_ZVAL(delay, 1, 0);
+
+               if (delay_p) {
+                       zval_ptr_dtor(&delay_p);
+               }
        }
 }
 /* }}} */
@@ -819,9 +851,13 @@ PHP_METHOD(HttpResponse, getBufferSize)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *size = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize));
+               zval *size_p, *size = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize), &size_p);
                
-               RETURN_ZVAL(size, 1, 0);
+               RETVAL_ZVAL(size, 1, 0);
+
+               if (size_p) {
+                       zval_ptr_dtor(&size_p);
+               }
        }
 }
 /* }}} */
@@ -932,7 +968,13 @@ PHP_METHOD(HttpResponse, getStream)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               RETURN_RESOURCE(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream))));
+               zval *stream_p;
+               
+               RETVAL_RESOURCE(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream), &stream_p)));
+
+               if (stream_p) {
+                       zval_ptr_dtor(&stream_p);
+               }
        }
 }
 /* }}} */
@@ -985,9 +1027,13 @@ PHP_METHOD(HttpResponse, getFile)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *the_file = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file));
+               zval *the_file_p, *the_file = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file), &the_file_p);
                
-               RETURN_ZVAL(the_file, 1, 0);
+               RETVAL_ZVAL(the_file, 1, 0);
+
+               if (the_file_p) {
+                       zval_ptr_dtor(&the_file_p);
+               }
        }
 }
 /* }}} */
@@ -1039,14 +1085,14 @@ PHP_METHOD(HttpResponse, send)
 
        /* capture mode */
        if (zval_is_true(GET_STATIC_PROP(catch))) {
-               zval *the_data;
+               zval *etag_p, *the_data;
 
                MAKE_STD_ZVAL(the_data);
                php_ob_get_buffer(the_data TSRMLS_CC);
                SET_STATIC_PROP(data, the_data);
                ZVAL_LONG(GET_STATIC_PROP(mode), SEND_DATA);
 
-               if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) {
+               if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag), &etag_p))) {
                        char *etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA);
                        if (etag) {
                                UPD_STATIC_PROP(string, eTag, etag);
@@ -1054,6 +1100,10 @@ PHP_METHOD(HttpResponse, send)
                        }
                }
                zval_ptr_dtor(&the_data);
+               
+               if (etag_p) {
+                       zval_ptr_dtor(&etag_p);
+               }
 
                clean_ob = 1;
        }
@@ -1067,19 +1117,23 @@ PHP_METHOD(HttpResponse, send)
 
        /* caching */
        if (zval_is_true(GET_STATIC_PROP(cache))) {
-               zval *cctl, *etag, *lmod;
+               zval *cctl, *cctl_p, *etag, *etag_p, *lmod, *lmod_p;
 
-               etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag));
-               lmod = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified));
-               cctl = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl));
+               etag = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag), &etag_p);
+               lmod = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified), &lmod_p);
+               cctl = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(cacheControl), &cctl_p);
 
                http_cache_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
                http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : time(NULL), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
+
+               if (etag_p) zval_ptr_dtor(&etag_p);
+               if (lmod_p) zval_ptr_dtor(&lmod_p);
+               if (cctl_p) zval_ptr_dtor(&cctl_p);
        }
 
        /* content type */
        {
-               zval *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType));
+               zval *ctype_p, *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType), &ctype_p);
                if (Z_STRLEN_P(ctype)) {
                        http_send_content_type(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype));
                } else {
@@ -1092,19 +1146,31 @@ PHP_METHOD(HttpResponse, send)
                                http_send_content_type("application/x-octetstream", lenof("application/x-octetstream"));
                        }
                }
+               if (ctype_p) {
+                       zval_ptr_dtor(&ctype_p);
+               }
        }
 
        /* content disposition */
        {
-               zval *cd = GET_STATIC_PROP(contentDisposition);
+               zval *cd_p, *cd = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentDisposition), &cd_p);
                if (Z_STRLEN_P(cd)) {
                        http_send_header_ex("Content-Disposition", lenof("Content-Disposition"), Z_STRVAL_P(cd), Z_STRLEN_P(cd), 1, NULL);
                }
+               if (cd_p) {
+                       zval_ptr_dtor(&cd_p);
+               }
        }
 
        /* throttling */
-       HTTP_G(send).buffer_size    = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize)));
-       HTTP_G(send).throttle_delay = Z_DVAL_P(convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay)));
+       {
+               zval *bsize_p, *bsize = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize), &bsize_p);
+               zval *delay_p, *delay = convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay), &delay_p);
+               HTTP_G(send).buffer_size    = Z_LVAL_P(bsize);
+               HTTP_G(send).throttle_delay = Z_DVAL_P(delay);
+               if (bsize_p) zval_ptr_dtor(&bsize_p);
+               if (delay_p) zval_ptr_dtor(&delay_p);
+       }
 
        /* gzip */
        HTTP_G(send).gzip_encoding = zval_is_true(GET_STATIC_PROP(gzip));
@@ -1117,22 +1183,29 @@ PHP_METHOD(HttpResponse, send)
        {
                case SEND_DATA:
                {
-                       zval *zdata = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(data));
-                       RETURN_SUCCESS(http_send_data_ex(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), 1));
+                       zval *zdata_p, *zdata = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(data), &zdata_p);
+                       RETVAL_SUCCESS(http_send_data_ex(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), 1));
+                       if (zdata_p) zval_ptr_dtor(&zdata_p);
+                       return;
                }
 
                case SEND_RSRC:
                {
                        php_stream *the_real_stream;
-                       zval *the_stream = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream));
+                       zval *the_stream_p, *the_stream = convert_to_type_ex(IS_LONG, GET_STATIC_PROP(stream), &the_stream_p);
                        the_stream->type = IS_RESOURCE;
                        php_stream_from_zval(the_real_stream, &the_stream);
-                       RETURN_SUCCESS(http_send_stream_ex(the_real_stream, 0, 1));
+                       RETVAL_SUCCESS(http_send_stream_ex(the_real_stream, 0, 1));
+                       if (the_stream_p) zval_ptr_dtor(&the_stream_p);
+                       return;
                }
 
                default:
                {
-                       RETURN_SUCCESS(http_send_file_ex(Z_STRVAL_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file))), 1));
+                       zval *file_p;
+                       RETVAL_SUCCESS(http_send_file_ex(Z_STRVAL_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(file), &file_p)), 1));
+                       if (file_p) zval_ptr_dtor(&file_p);
+                       return;
                }
        }
 }
index bc5185161a0f102afab995025a2a2d40b97ec0ad..f6cd59ffe624278ddc42ceae916ef54584286396 100644 (file)
@@ -144,9 +144,10 @@ static inline zval *_convert_to_type(int type, zval *z)
        }
        return z;
 }
-#define convert_to_type_ex(t, z) _convert_to_type_ex((t), (z))
-static inline zval *_convert_to_type_ex(int type, zval *z)
+#define convert_to_type_ex(t, z, p) _convert_to_type_ex((t), (z), (p))
+static inline zval *_convert_to_type_ex(int type, zval *z, zval **p)
 {
+       *p = z;
        if (Z_TYPE_P(z) != type) {
                switch (type)
                {
@@ -159,6 +160,11 @@ static inline zval *_convert_to_type_ex(int type, zval *z)
                        case IS_OBJECT: convert_to_object_ex(&z);       break;
                }
        }
+       if (*p == z) {
+               *p = NULL;
+       } else {
+               *p = z;
+       }
        return z;
 }