- ditch leak when throwing exceptions
authorMichael Wallner <mike@php.net>
Fri, 7 Oct 2005 13:31:42 +0000 (13:31 +0000)
committerMichael Wallner <mike@php.net>
Fri, 7 Oct 2005 13:31:42 +0000 (13:31 +0000)
- add simple test

http_api.c
tests/exceptions.phpt [new file with mode: 0644]

index 999826dfa7af7a6c89bc8bf72e27519ef1d0063c..c5c63f95cd129ac8a72d8fc310d413971e27c0fd 100644 (file)
@@ -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 (file)
index 0000000..af48fde
--- /dev/null
@@ -0,0 +1,59 @@
+--TEST--
+exceptions
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkver(5);
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+ini_set('http.only_exceptions', true);
+
+$e = array(
+        HTTP_E_RUNTIME                         => '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