MFH: fix memory leaks and untermiated string issue with HttpMessage
authorMichael Wallner <mike@php.net>
Wed, 18 Mar 2009 10:23:23 +0000 (10:23 +0000)
committerMichael Wallner <mike@php.net>
Wed, 18 Mar 2009 10:23:23 +0000 (10:23 +0000)
http_message_api.c
http_message_object.c

index e85774fbb1c7d25a191554180b5bea75a9aefbb5..e091a84350e6b1ef769277cd133d90cceabafe14 100644 (file)
@@ -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
index 5b96d218076ee4caea914895a209b2b813e9fdae..70bf7f0c06385ae58a04ea11f60c72e7d46b6a6f 100644 (file)
@@ -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) {