From: Michael Wallner Date: Tue, 16 Jul 2013 08:46:01 +0000 (+0000) Subject: fix segfault when initializing a request message with a body X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~26 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=847c94ac2eef3c43200a7e066a7ee823d580b20c;p=m6w6%2Fext-http fix segfault when initializing a request message with a body TODO: convert phpunit tests to PHPTs --- diff --git a/php_http_client_request.c b/php_http_client_request.c index 2d427a3..86843e6 100644 --- a/php_http_client_request.c +++ b/php_http_client_request.c @@ -34,10 +34,7 @@ static PHP_METHOD(HttpClientRequest, __construct) php_http_message_body_object_t *body_obj = NULL; if (zbody) { - body_obj = zend_object_store_get_object(zbody TSRMLS_CC); - Z_OBJ_ADDREF_P(zbody); - obj->body->zv = Z_OBJVAL_P(zbody); - php_http_message_body_addref(body_obj->body); + php_http_message_object_set_body(obj, zbody TSRMLS_CC); } if (obj->message) { diff --git a/php_http_message.c b/php_http_message.c index 80c488e..68ba91a 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -774,9 +774,12 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval if (msg_obj->body) { zend_objects_store_del_ref_by_handle(msg_obj->body->zv.handle TSRMLS_CC); } - php_http_message_body_free(&msg_obj->message->body); - - msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC); + if (msg_obj->message) { + php_http_message_body_free(&msg_obj->message->body); + msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC); + } else { + msg_obj->message = php_http_message_init(NULL, 0, php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC) TSRMLS_CC); + } msg_obj->body = body_obj; if (tmp) { diff --git a/phpunit/CookieTest.php b/phpunit/CookieTest.php index 11342ad..d569c75 100644 --- a/phpunit/CookieTest.php +++ b/phpunit/CookieTest.php @@ -1,5 +1,7 @@