From 602fe384803e6f489c6e551722fff770e80ebf2d Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 2 Nov 2005 16:32:01 +0000 Subject: [PATCH] - ensure proper message deallocation --- http_api.c | 13 ++++++------- http_message_api.c | 2 +- php_http_std_defs.h | 12 ++++++------ tests/HttpMessage_001.phpt | 26 ++++++++++++++++---------- tests/HttpRequest_003.phpt | 7 ++++++- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/http_api.c b/http_api.c index 55f5e88..8030c0f 100644 --- a/http_api.c +++ b/http_api.c @@ -249,13 +249,12 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC) /* {{{ STATUS http_exit(int, char*, char*) */ STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC) { - if (status || send_header) { - if (SUCCESS != http_send_status_header(status, send_header ? header : NULL)) { - http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : ""); - STR_FREE(header); - STR_FREE(body); - return FAILURE; - } + if ( (send_header && (SUCCESS != http_send_status_header(status, header))) || + (!send_header && status && (SUCCESS != http_send_status(status)))) { + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : ""); + STR_FREE(header); + STR_FREE(body); + return FAILURE; } if (php_header(TSRMLS_C) && body) { diff --git a/http_message_api.c b/http_message_api.c index 6dd2067..7fe5aec 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -259,7 +259,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char # endif /* HTTP_HAVE_ZLIB */ } - if (decoded && decoded_len) { + if (decoded) { zval *len; char *tmp; int tmp_len; diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 8960485..40dc8c7 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -66,17 +66,17 @@ typedef int STATUS; RETVAL_OBJECT(o); \ return #define RETVAL_OBJVAL(ov) \ - ZVAL_OBJVAL(return_value, ov) + ZVAL_OBJVAL(return_value, ov) \ + if (Z_OBJ_HT_P(return_value)->add_ref) { \ + Z_OBJ_HT_P(return_value)->add_ref(return_value TSRMLS_CC); \ + } #define RETURN_OBJVAL(ov) \ RETVAL_OBJVAL(ov); \ return #define ZVAL_OBJVAL(zv, ov) \ (zv)->type = IS_OBJECT; \ - (zv)->value.obj = (ov); \ - if (Z_OBJ_HT_P(zv)->add_ref) { \ - Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \ - } - + (zv)->value.obj = (ov); + /* function accepts no args */ #define NO_ARGS \ if (ZEND_NUM_ARGS()) { \ diff --git a/tests/HttpMessage_001.phpt b/tests/HttpMessage_001.phpt index eda359c..1ceda68 100644 --- a/tests/HttpMessage_001.phpt +++ b/tests/HttpMessage_001.phpt @@ -12,7 +12,7 @@ $m = new HttpMessage( "HTTP/1.1 301\r\n". "Location: /anywhere\r\n". "HTTP/1.1 302\r\n". - "Location: /somwhere\r\n". + "Location: /somewhere\r\n". "HTTP/1.1 206\r\n". "Content-Range: bytes=2-3\r\n". "Transfer-Encoding: chunked\r\n". @@ -23,30 +23,36 @@ $m = new HttpMessage( ); var_dump($m->getBody()); -var_dump($m->toString(true)); var_dump(HttpMessage::fromString($m->toString(true))->toString(true)); +do { + var_dump($m->toString()); +} while ($m = $m->getParentMessage()); + +echo "Done\n"; ?> --EXPECTF-- %sTEST string(1) "X" -string(134) "HTTP/1.1 301 +string(135) "HTTP/1.1 301 Location: /anywhere HTTP/1.1 302 -Location: /somwhere +Location: /somewhere HTTP/1.1 206 Content-Range: bytes=2-3 Content-Length: 1 X " -string(134) "HTTP/1.1 301 -Location: /anywhere -HTTP/1.1 302 -Location: /somwhere -HTTP/1.1 206 +string(64) "HTTP/1.1 206 Content-Range: bytes=2-3 Content-Length: 1 X " - +string(36) "HTTP/1.1 302 +Location: /somewhere +" +string(35) "HTTP/1.1 301 +Location: /anywhere +" +Done diff --git a/tests/HttpRequest_003.phpt b/tests/HttpRequest_003.phpt index d352b18..bed6735 100644 --- a/tests/HttpRequest_003.phpt +++ b/tests/HttpRequest_003.phpt @@ -13,8 +13,13 @@ echo "-TEST\n"; $r = new HttpRequest('https://ssl.arweb.info/iworks/data.txt'); $r->send(); var_dump($r->getResponseBody()); +var_dump(is_object($r->getResponseMessage())); +var_dump(is_object($r->getResponseMessage())); +var_dump(is_object($r->getResponseMessage())); ?> --EXPECTF-- %sTEST string(10) "1234567890" - +bool(true) +bool(true) +bool(true) -- 2.30.2