From: Dmitry Stogov Date: Fri, 24 Mar 2006 10:11:49 +0000 (+0000) Subject: Fixed bug #36840 (Memory leak if cast operator throws an exception that is caught) X-Git-Tag: RELEASE_1_3~278 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4767e90a473a83bf6bcfdfb6283527691f90f49f;p=php Fixed bug #36840 (Memory leak if cast operator throws an exception that is caught) --- diff --git a/NEWS b/NEWS index 0c734b1a82..8d437858c7 100644 --- a/NEWS +++ b/NEWS @@ -43,5 +43,7 @@ PHP NEWS the part of haystack before or after first occurence of needle. (Johannes) - Added possibility to check in which extension an internal function was defined using reflection API. (Johannes) +- Fixed bug #36840 (Memory leak if cast operator throws an exception that is + caught). (Dmitry) - Fixed bug #36630 (umask not reset at the end of the request). (Ilia) - Fixed bug #34286 (__toString() behavior is inconsistent). (Marcus) diff --git a/Zend/zend_unicode.c b/Zend/zend_unicode.c index 233f73fed7..69ae8d30b7 100644 --- a/Zend/zend_unicode.c +++ b/Zend/zend_unicode.c @@ -374,14 +374,18 @@ ZEND_API int zval_unicode_to_string(zval *string, UConverter *conv TSRMLS_DC) num_conv = zend_convert_from_unicode(conv, &s, &s_len, u, u_len, &status); - ZVAL_STRINGL(string, s, s_len, 0); - if (U_FAILURE(status)) { int32_t offset = u_countChar32(u, num_conv)-1; + + if (s) { + efree(s); + } zend_raise_conversion_error_ex("Could not convert Unicode string to binary string", conv, offset, (UG(from_u_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC); retval = FAILURE; } + ZVAL_STRINGL(string, s, s_len, 0); + efree((UChar*)u); return retval; }