fix leaks
[m6w6/ext-http] / php_http_message.c
index caf9ee82786347b7f4fb491ae928e5d22dc3e995..75d7fe5396e9e4ab41c9125a040bbb559d4e4c30 100644 (file)
@@ -275,6 +275,8 @@ void php_http_message_update_headers(php_http_message_t *msg)
 
        if (php_http_message_body_stream(msg->body)->readfilters.head) {
                /* if a read stream filter is attached to the body the caller must also care for the headers */
+       } else if (php_http_message_header(msg, ZEND_STRL("Content-Range"))) {
+               /* don't mess around with a Content-Range message */
        } else if ((size = php_http_message_body_size(msg->body))) {
                ZVAL_LONG(&h, size);
                zend_hash_str_update(&msg->hdrs, "Content-Length", lenof("Content-Length"), &h);
@@ -299,6 +301,7 @@ void php_http_message_update_headers(php_http_message_t *msg)
                }
        } else if ((cl = php_http_message_header_string(msg, ZEND_STRL("Content-Length")))) {
                if (!zend_string_equals_literal(cl, "0")) {
+                       /* body->size == 0, so get rid of old Content-Length */
                        zend_hash_str_del(&msg->hdrs, ZEND_STRL("Content-Length"));
                }
                zend_string_release(cl);
@@ -493,7 +496,6 @@ void php_http_message_free(php_http_message_t **message)
 
 static zval *php_http_message_object_read_prop(zval *object, zval *member, int type, void **cache_slot, zval *rv);
 static void php_http_message_object_write_prop(zval *object, zval *member, zval *value, void **cache_slot);
-static HashTable *php_http_message_object_get_props(zval *object);
 
 static zend_object_handlers php_http_message_object_handlers;
 static HashTable php_http_message_object_prophandlers;
@@ -604,9 +606,8 @@ static void php_http_message_object_prophandler_set_headers(php_http_message_obj
 
        if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) {
                convert_to_array_ex(value);
-       } else {
-               headers = HASH_OF(value);
        }
+       headers = HASH_OF(value);
 
        zend_hash_clean(&obj->message->hdrs);
        array_copy(headers, &obj->message->hdrs);
@@ -688,7 +689,8 @@ void php_http_message_object_reverse(zval *zmsg, zval *return_value)
 
                /* add ref, because we previously have not been a parent message */
                Z_ADDREF_P(zmsg);
-               RETVAL_OBJECT(&objects[last]->zo, 1);
+               /* no addref, because we've been a parent message previously */
+               RETVAL_OBJECT(&objects[last]->zo, 0);
 
                efree(objects);
        } else {
@@ -798,7 +800,7 @@ php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce,
 {
        php_http_message_object_t *o;
 
-       o = ecalloc(1, sizeof(php_http_message_object_t) + (ce->default_properties_count - 1) * sizeof(zval));
+       o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
        zend_object_std_init(&o->zo, ce);
        object_properties_init(&o->zo, ce);
 
@@ -806,8 +808,6 @@ php_http_message_object_t *php_http_message_object_new_ex(zend_class_entry *ce,
                o->message = msg;
                if (msg->parent) {
                        o->parent = php_http_message_object_new_ex(ce, msg->parent);
-                       /* not assigned to any zval, so refcount is 0 */
-                       --GC_REFCOUNT(&o->parent->zo);
                }
                o->body = php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL));
        }
@@ -897,7 +897,7 @@ static void php_http_message_object_write_prop(zval *object, zval *member, zval
        zend_string_release(member_name);
 }
 
-static HashTable *php_http_message_object_get_props(zval *object)
+static HashTable *php_http_message_object_get_debug_info(zval *object, int *is_temp)
 {
        zval tmp;
        php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
@@ -906,13 +906,14 @@ static HashTable *php_http_message_object_get_props(zval *object)
        size_t ver_len, url_len = 0;
 
        PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+       *is_temp = 0;
        
 #define UPDATE_PROP(name_str, action_with_tmp) \
        do { \
                zend_property_info *pi; \
                if ((pi = zend_hash_str_find_ptr(&obj->zo.ce->properties_info, name_str, lenof(name_str)))) { \
                        action_with_tmp; \
-                       zend_hash_update(props, pi->name, &tmp); \
+                       zend_hash_update_ind(props, pi->name, &tmp); \
                } \
        } while(0)
 
@@ -1109,15 +1110,18 @@ static PHP_METHOD(HttpMessage, getHeader)
 
                if ((header = php_http_message_header(obj->message, header_str, header_len))) {
                        if (!header_ce) {
-                               RETURN_ZVAL(header, 1, 1);
+                               RETURN_ZVAL_FAST(header);
                        } else if (instanceof_function(header_ce, php_http_header_class_entry)) {
+                               php_http_object_method_t cb;
                                zval argv[2];
 
                                ZVAL_STRINGL(&argv[0], header_str, header_len);
                                ZVAL_COPY(&argv[1], header);
 
                                object_init_ex(return_value, header_ce);
-                               php_http_method_call(return_value, ZEND_STRL("__construct"), 2, argv, NULL);
+                               php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct"));
+                               php_http_object_method_call(&cb, return_value, NULL, 2, argv);
+                               php_http_object_method_dtor(&cb);
 
                                zval_ptr_dtor(&argv[0]);
                                zval_ptr_dtor(&argv[1]);
@@ -1968,7 +1972,7 @@ PHP_MINIT_FUNCTION(http_message)
        php_http_message_object_handlers.free_obj = php_http_message_object_free;
        php_http_message_object_handlers.read_property = php_http_message_object_read_prop;
        php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
-       php_http_message_object_handlers.get_properties = php_http_message_object_get_props;
+       php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
        php_http_message_object_handlers.get_property_ptr_ptr = NULL;
 
        zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);