fixup php_http_params
authorMichael Wallner <mike@php.net>
Sun, 18 Jan 2015 16:48:09 +0000 (17:48 +0100)
committerMichael Wallner <mike@php.net>
Sun, 18 Jan 2015 16:48:09 +0000 (17:48 +0100)
php_http_client_request.c
php_http_client_response.c
php_http_env_response.c
php_http_message_parser.c
php_http_params.c

index f665b207be4b4b0948f43fe41332e676cebad2c9..68f627e7d0514be7ca6d10732b59a4e7fa4b3832 100644 (file)
@@ -98,7 +98,7 @@ static PHP_METHOD(HttpClientRequest, getContentType)
                php_http_message_update_headers(obj->message);
                zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"));
                if (zct) {
-                       RETURN_ZVAL(zct, 0, 1);
+                       RETURN_ZVAL_FAST(zct);
                }
        }
 }
index 1fcdca5a4e24bff5dd960254c7effd93dc7780bc..b8efb8b6a63dd2faf093aab606b4e5427e0ccada 100644 (file)
@@ -74,7 +74,6 @@ static PHP_METHOD(HttpClientResponse, getCookies)
                        }
                        zend_string_release(zs);
                }
-               zval_ptr_dtor(header);
        }
 
        if (allowed_extras) {
index 34bc75393732a41b6aff9c86d48b0217da577503..c8a31e070bd0b1b38fddbb60aadfe841738c9bf3 100644 (file)
@@ -119,6 +119,7 @@ static void set_cookie(zval *options, zval *zcookie_new TSRMLS_DC)
                }
                array_init_size(zcookies_set, zend_hash_num_elements(&obj->list->cookies));
        } else {
+               Z_ADDREF_P(zcookies_set);
                SEPARATE_ZVAL(zcookies_set);
        }
 
@@ -465,7 +466,6 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                                zval *tmp = zoption;
                                SEPARATE_ZVAL(tmp);
                                convert_to_array(tmp);
-                               zval_ptr_dtor(zoption);
                                zoption = tmp;
                        }
 
index fb5b26fde910562aef7da6fa1ebe5abb5de020da..2438fc13e31aaa427a88d0e21403e565c7568d2c 100644 (file)
@@ -250,13 +250,16 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p
                                zval h, *h_loc = NULL, *h_con = NULL, *h_cl, *h_cr, *h_te, *h_ce;
 
                                if ((h_te = php_http_message_header(*message, ZEND_STRL("Transfer-Encoding")))) {
+                                       Z_TRY_ADDREF_P(h_te);
                                        zend_hash_str_update(&(*message)->hdrs, "X-Original-Transfer-Encoding", lenof("X-Original-Transfer-Encoding"), h_te);
                                        zend_hash_str_del(&(*message)->hdrs, "Transfer-Encoding", lenof("Transfer-Encoding"));
                                }
                                if ((h_cl = php_http_message_header(*message, ZEND_STRL("Content-Length")))) {
+                                       Z_TRY_ADDREF_P(h_cl);
                                        zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Length", lenof("X-Original-Content-Length"), h_cl);
                                }
                                if ((h_cr = php_http_message_header(*message, ZEND_STRL("Content-Range")))) {
+                                       Z_TRY_ADDREF_P(h_cr);
                                        zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), h_cr);
                                        zend_hash_str_del(&(*message)->hdrs, "Content-Range", lenof("Content-Range"));
                                }
@@ -298,10 +301,9 @@ php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_p
                                                } else {
                                                        parser->inflate = php_http_encoding_stream_init(NULL, php_http_encoding_stream_get_inflate_ops(), 0);
                                                }
+                                               Z_TRY_ADDREF_P(h_ce);
                                                zend_hash_str_update(&(*message)->hdrs, "X-Original-Content-Encoding", lenof("X-Original-Content-Encoding"), h_ce);
                                                zend_hash_str_del(&(*message)->hdrs, "Content-Encoding", lenof("Content-Encoding"));
-                                       } else {
-                                               zval_ptr_dtor(h_ce);
                                        }
                                }
 
index 2f73cb93d8e8d7af676fbe83f65c0564c2ad4458..1be8e55ecd1b5baa34e70a252cb97f60d63454e5 100644 (file)
@@ -67,7 +67,7 @@ static inline void prepare_escaped(zval *zv)
 {
        if (Z_TYPE_P(zv) == IS_STRING) {
                size_t len = Z_STRLEN_P(zv);
-               zend_string *stripped = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), 1,
+               zend_string *stripped = php_addcslashes(Z_STRVAL_P(zv), Z_STRLEN_P(zv), 0,
                                ZEND_STRL("\0..\37\173\\\""));
 
                if (len != stripped->len || strpbrk(stripped->val, "()<>@,;:\"[]?={} ")) {
@@ -843,8 +843,9 @@ php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *
                                zvalue = tmp;
                        } else if (zvalue == zparam) {
                                continue;
+                       } else {
+                               zvalue = zparam;
                        }
-                       zvalue = zparam;
                }
 
                if (Z_TYPE_P(zvalue) == IS_ARRAY) {
@@ -871,15 +872,17 @@ php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *
 
 php_http_params_token_t **php_http_params_separator_init(zval *zv)
 {
-       zval *sep;
+       zval *sep, ztmp;
        php_http_params_token_t **ret, **tmp;
 
        if (!zv) {
                return NULL;
        }
 
-       SEPARATE_ZVAL(zv);
+       ZVAL_DUP(&ztmp, zv);
+       zv = &ztmp;
        convert_to_array(zv);
+
        ret = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(zv)) + 1, sizeof(*ret));
 
        tmp = ret;
@@ -895,7 +898,8 @@ php_http_params_token_t **php_http_params_separator_init(zval *zv)
                zend_string_release(zs);
        }
        ZEND_HASH_FOREACH_END();
-       zval_ptr_dtor(zv);
+
+       zval_ptr_dtor(&ztmp);
 
        *tmp = NULL;
        return ret;
@@ -957,6 +961,8 @@ PHP_METHOD(HttpParams, __construct)
                                default:
                                        zs = zval_get_string(zparams);
                                        if (zs->len) {
+                                               zval tmp;
+
                                                php_http_params_opts_t opts = {
                                                        {zs->val, zs->len},
                                                        php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0)),
@@ -965,19 +971,24 @@ PHP_METHOD(HttpParams, __construct)
                                                        {{0}}, flags
                                                };
 
-                                               array_init(zparams);
-                                               php_http_params_parse(Z_ARRVAL_P(zparams), &opts);
-                                               zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
+                                               array_init(&tmp);
+                                               php_http_params_parse(Z_ARRVAL(tmp), &opts);
+                                               zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
+                                               zval_ptr_dtor(&tmp);
 
                                                php_http_params_separator_free(opts.param);
                                                php_http_params_separator_free(opts.arg);
                                                php_http_params_separator_free(opts.val);
                                        }
+                                       zend_string_release(zs);
                                        break;
                        }
                } else {
-                       array_init(zparams);
-                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
+                       zval tmp;
+
+                       array_init(&tmp);
+                       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), &tmp);
+                       zval_ptr_dtor(&tmp);
                }
        }
        zend_restore_error_handling(&zeh);
@@ -1094,7 +1105,6 @@ PHP_METHOD(HttpParams, offsetUnset)
 
        if (Z_TYPE_P(zparams) == IS_ARRAY) {
                zend_symtable_del(Z_ARRVAL_P(zparams), name);
-               zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
        }
 }
 
@@ -1112,29 +1122,22 @@ PHP_METHOD(HttpParams, offsetSet)
        }
 
        zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0);
-       SEPARATE_ZVAL(zparams);
        convert_to_array(zparams);
 
        if (name->len) {
                if (Z_TYPE_P(nvalue) == IS_ARRAY) {
-                       zval *new_zparam;
-
                        if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
-                               new_zparam = zparam;
-                               SEPARATE_ZVAL(new_zparam);
-                               convert_to_array(new_zparam);
-                               array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(new_zparam), 0, 0);
+                               convert_to_array(zparam);
+                               array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(zparam), 0, 0);
                        } else {
-                               new_zparam = nvalue;
-                               Z_TRY_ADDREF_P(new_zparam);
+                               Z_TRY_ADDREF_P(nvalue);
+                               add_assoc_zval_ex(zparams, name->val, name->len, nvalue);
                        }
-                       add_assoc_zval_ex(zparams, name->val, name->len, new_zparam);
                } else {
                        zval tmp;
 
                        if ((zparam = zend_symtable_find(Z_ARRVAL_P(zparams), name))) {
-                               tmp = *zparam;
-                               SEPARATE_ZVAL(&tmp);
+                               ZVAL_DUP(&tmp, zparam);
                                convert_to_array(&tmp);
                        } else {
                                array_init(&tmp);
@@ -1153,9 +1156,6 @@ PHP_METHOD(HttpParams, offsetSet)
                add_assoc_zval_ex(zparams, zs->val, zs->len, &arr);
                zend_string_release(zs);
        }
-
-       zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams);
-       zval_ptr_dtor(zparams);
 }
 
 static zend_function_entry php_http_params_methods[] = {