X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_message_body.c;h=e630176176f92e33c1765574615eda197179994c;hp=3ab57f27e4c57f4e8f5a5bfe1650409b038f5030;hb=7a492dc2544d408eb65fd38cb644fd6adde3bbe9;hpb=d5f3f3f2917a257a39a6b8893c6ae203b3dda3df diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index 3ab57f2..e630176 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -46,10 +46,11 @@ php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **bo if (stream) { body->res = stream->res; + ++GC_REFCOUNT(body->res); } else { body->res = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff)->res; } - ++GC_REFCOUNT(body->res); + php_stream_auto_cleanup(php_http_message_body_stream(body)); if (body_ptr) { *body_ptr = body; @@ -89,8 +90,9 @@ void php_http_message_body_free(php_http_message_body_t **body_ptr) { if (*body_ptr) { php_http_message_body_t *body = *body_ptr; - if (!--body->refcount) { + zend_list_delete(body->res); + body->res = NULL; PTR_FREE(body->boundary); efree(body); } @@ -568,8 +570,6 @@ php_http_message_body_object_t *php_http_message_body_object_new_ex(zend_class_e if (body) { o->body = body; - php_stream_to_zval(php_http_message_body_stream(o->body), o->gc); - } o->zo.handlers = &php_http_message_body_object_handlers; @@ -595,12 +595,18 @@ static HashTable *php_http_message_body_object_get_gc(zval *object, zval **table HashTable *props = Z_OBJPROP_P(object); uint32_t count = zend_hash_num_elements(props); - *n = 1; + obj->gc = erealloc(obj->gc, (1 + count) * sizeof(zval)); + + if (php_http_message_body_stream(obj->body)) { + *n = 1; + php_stream_to_zval(php_http_message_body_stream(obj->body), obj->gc); + } else { + *n = 0; + } + if (count) { zval *val; - obj->gc = erealloc(obj->gc, (*n + count) * sizeof(zval)); - ZEND_HASH_FOREACH_VAL(props, val) { ZVAL_COPY_VALUE(&obj->gc[(*n)++], val);