php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch 0001-Bug-61785-Memory-leak-when-access-a-non-exists-file-.patch for Built-in web server Bug #61785

Patch version 2012-04-20 09:50 UTC

Return to Bug #61785 | Download this patch
Patch Revisions:

Developer: reeze.xia@gmail.com

From b8e70ac0416d00d77c17f5465c35fddb9bd0a3b6 Mon Sep 17 00:00:00 2001
From: reeze <reeze.xia@gmail.com>
Date: Fri, 20 Apr 2012 17:33:26 +0800
Subject: [PATCH 1/2] Bug #61785 (Memory leak when access a non-exists file
 without route)


Signed-off-by: reeze <reeze.xia@gmail.com>
---
 sapi/cli/php_cli_server.c              |    3 +++
 sapi/cli/tests/php_cli_server_018.phpt |   39 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 sapi/cli/tests/php_cli_server_018.phpt

diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index 79ccea3..647d37e 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -1781,11 +1781,14 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server
 			php_output_discard(TSRMLS_C);
 			if (!SG(sapi_started)) {
 				static int (*send_header_func)(sapi_headers_struct * TSRMLS_DC);
+				unsigned char send_default_content_type = SG(sapi_headers).send_default_content_type;
 				send_header_func = sapi_module.send_headers;
 				/* we don't want the header to be sent now */
 				sapi_module.send_headers = sapi_cli_server_discard_headers;
+				SG(sapi_headers).send_default_content_type = 0;
 				php_output_deactivate(TSRMLS_C);
 				sapi_module.send_headers = send_header_func;
+				SG(sapi_headers).send_default_content_type = send_default_content_type;
 			}
 			if (style && Z_STRVAL_P(style)) {
 				char *block = pestrndup(Z_STRVAL_P(style), Z_STRLEN_P(style), 1);
diff --git a/sapi/cli/tests/php_cli_server_018.phpt b/sapi/cli/tests/php_cli_server_018.phpt
new file mode 100644
index 0000000..5df685b
--- /dev/null
+++ b/sapi/cli/tests/php_cli_server_018.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Bug #60591 (Memory leak when access a non-exists file without router)
+--DESCRIPTION--
+this is an indirect test for bug 60691, since mem leak is reproted in the server side
+and require php compiled with --enable-debug
+--SKIPIF--
+<?php
+include "skipif.inc"; 
+?>
+--FILE--
+<?php
+include "php_cli_server.inc";
+php_cli_server_start(NULL, true);
+
+list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
+$port = intval($port)?:80;
+
+$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
+if (!$fp) {
+  die("connect failed");
+}
+
+if(fwrite($fp, <<<HEADER
+POST /no-exists.jpg HTTP/1.1
+Host: {$host}
+
+
+HEADER
+)) {
+	while (!feof($fp)) {
+		echo fgets($fp);
+        break;
+	}
+}
+
+fclose($fp);
+?>
+--EXPECTF--
+HTTP/1.1 404 Not Found
-- 
1.7.9.3

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 20:02:01 2014 UTC