From: Michael Wallner Date: Fri, 7 Oct 2005 13:31:42 +0000 (+0000) Subject: - ditch leak when throwing exceptions X-Git-Tag: RELEASE_0_15_0~33 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=a896cda2c56ae9525e8d99622841350a1fb73926;hp=c51384deca17beea51a6efdd82ac9efb551220eb - ditch leak when throwing exceptions - add simple test --- diff --git a/http_api.c b/http_api.c index 999826d..c5c63f9 100644 --- a/http_api.c +++ b/http_api.c @@ -176,6 +176,7 @@ void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...) vspprintf(&message, 0, format, args); zend_throw_exception(http_exception_get_for_code(code), message, code TSRMLS_CC); + efree(message); } else #endif php_verror(NULL, "", type, format, args TSRMLS_CC); diff --git a/tests/exceptions.phpt b/tests/exceptions.phpt new file mode 100644 index 0000000..af48fde --- /dev/null +++ b/tests/exceptions.phpt @@ -0,0 +1,59 @@ +--TEST-- +exceptions +--SKIPIF-- + +--FILE-- + 'Runtime', + HTTP_E_INVALID_PARAM => 'InvalidParam', + HTTP_E_HEADER => 'Header', + HTTP_E_MALFORMED_HEADERS => 'MalformedHeaders', + HTTP_E_REQUEST_METHOD => 'RequestMethod', + HTTP_E_MESSAGE_TYPE => 'MessageType', + HTTP_E_ENCODING => 'Encoding', + HTTP_E_REQUEST => 'Request', + HTTP_E_REQUEST_POOL => 'RequestPool', + HTTP_E_SOCKET => 'Socket', + HTTP_E_RESPONSE => 'Response', + HTTP_E_URL => 'Url', +); + +foreach ($e as $i => $c) { + try { + $n = "Http{$c}Exception"; + throw new $n; + } catch (HttpException $x) { + printf("%2d: %s\n", $i, get_class($x)); + } +} +try { + $tmp = http_get(null); +} catch (HttpRequestException $x) { + printf("%s (%d)\n", $x->getMessage(), $x->getCode()); +} +echo "Done\n"; +?> +--EXPECTF-- +%sTEST + 1: HttpRuntimeException + 2: HttpInvalidParamException + 3: HttpHeaderException + 4: HttpMalformedHeadersException + 5: HttpRequestMethodException + 6: HttpMessageTypeException + 7: HttpEncodingException + 8: HttpRequestException + 9: HttpRequestPoolException +10: HttpSocketException +11: HttpResponseException +12: HttpUrlException +Could not perform request: URL using bad/illegal format or missing URL (8) +Done