From 2ca49a0aa5397e8ca76d31fd745eb78efbe144f1 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 18 Mar 2009 10:23:23 +0000 Subject: [PATCH] MFH: fix memory leaks and untermiated string issue with HttpMessage --- http_message_api.c | 21 +++++++++++---------- http_message_object.c | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/http_message_api.c b/http_message_api.c index e85774f..e091a84 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -601,17 +601,17 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC) #ifdef HTTP_HAVE_CURL char *uri = NULL; http_request request; - zval **zhost, options, headers; - - INIT_PZVAL(&options); - INIT_PZVAL(&headers); - array_init(&options); - array_init(&headers); - zend_hash_copy(Z_ARRVAL(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - add_assoc_zval(&options, "headers", &headers); + zval **zhost, *options, *headers; + + MAKE_STD_ZVAL(options); + MAKE_STD_ZVAL(headers); + array_init(options); + array_init(headers); + zend_hash_copy(Z_ARRVAL_P(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + add_assoc_zval(options, "headers", headers); /* check host header */ - if (SUCCESS == zend_hash_find(&message->hdrs, "Host", sizeof("Host"), (void *) &zhost)) { + if (SUCCESS == zend_hash_find(&message->hdrs, "Host", sizeof("Host"), (void *) &zhost) && Z_TYPE_PP(zhost) == IS_STRING) { char *colon = NULL; php_url parts, *url = php_url_parse(message->http.info.request.url); @@ -637,7 +637,7 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC) http_request_init_ex(&request, NULL, request.meth, uri); request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, PHPSTR_VAL(message), PHPSTR_LEN(message), 0); - if (SUCCESS == (rs = http_request_prepare(&request, NULL))) { + if (SUCCESS == (rs = http_request_prepare(&request, Z_ARRVAL_P(options)))) { http_request_exec(&request); } http_request_dtor(&request); @@ -647,6 +647,7 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC) message->http.info.request.method); } efree(uri); + zval_ptr_dtor(&options); #else http_error(HE_WARNING, HTTP_E_RUNTIME, "HTTP requests not supported - ext/http was not linked against libcurl."); #endif diff --git a/http_message_object.c b/http_message_object.c index 5b96d21..70bf7f0 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -803,7 +803,6 @@ PHP_METHOD(HttpMessage, setBody) if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) { phpstr_dtor(PHPSTR(obj->message)); phpstr_from_string_ex(PHPSTR(obj->message), body, len); - phpstr_fix(PHPSTR(obj->message)); } } /* }}} */ @@ -1277,6 +1276,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) zval_ptr_dtor(&array); if (PHPSTR_VAL(obj->message) && PHPSTR_LEN(obj->message)) { + phpstr_fix(PHPSTR(obj->message)); INIT_PZVAL(&body); ZVAL_STRINGL(&body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 0); if (method != HTTP_POST) { -- 2.30.2