]> granicus.if.org Git - php/commitdiff
Better but incomplete fix for bug #36840
authorDmitry Stogov <dmitry@php.net>
Mon, 27 Mar 2006 07:35:05 +0000 (07:35 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 27 Mar 2006 07:35:05 +0000 (07:35 +0000)
NEWS
Zend/zend_unicode.c

diff --git a/NEWS b/NEWS
index 265e9865731b72b3406a617f80666098189afbd9..03a64ab3311446649a5023bdb018e245ec6907bb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -45,7 +45,5 @@ PHP                                                                        NEWS
   defined using reflection API. (Johannes)
 - Added second optional parameter to stream_context_create() to set params
   during context creation. (Sara)
-- 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)
index 99af389b80c61d823e5cc09e154a2452d7160533..4d56075c2a5c63862993f7bd916df05e9db2b657 100644 (file)
@@ -442,7 +442,6 @@ ZEND_API void zend_raise_conversion_error_ex(char *message, UConverter *conv, ze
 ZEND_API int zval_unicode_to_string(zval *string, UConverter *conv TSRMLS_DC)
 {
        UErrorCode status = U_ZERO_ERROR;
-       int retval = TRUE;
        char *s = NULL;
        int s_len;
        int num_conv;
@@ -455,19 +454,18 @@ ZEND_API int zval_unicode_to_string(zval *string, UConverter *conv TSRMLS_DC)
        if (U_FAILURE(status)) {
                int32_t offset = u_countChar32(u, num_conv);
 
-               /* XXX needs to be fixed, but a leak is better than invalid memory
+               zend_raise_conversion_error_ex("Could not convert Unicode string to binary string", conv, ZEND_FROM_UNICODE, offset, (UG(from_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC);
                if (s) {
                        efree(s);
                }
-               */
-               zend_raise_conversion_error_ex("Could not convert Unicode string to binary string", conv, ZEND_FROM_UNICODE, offset, (UG(from_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC);
-               retval = FAILURE;
+               ZVAL_EMPTY_STRING(string);
+               efree((UChar*)u);
+               return FAILURE;
+       } else {
+               ZVAL_STRINGL(string, s, s_len, 0);
+               efree((UChar*)u);
+               return SUCCESS;
        }
-
-       ZVAL_STRINGL(string, s, s_len, 0);
-
-       efree((UChar*)u);
-       return retval;
 }
 /* }}} */
 
@@ -486,13 +484,17 @@ ZEND_API int zval_string_to_unicode_ex(zval *string, UConverter *conv TSRMLS_DC)
 
        if (U_FAILURE(status)) {
                zend_raise_conversion_error_ex("Could not convert binary string to Unicode string", conv, ZEND_TO_UNICODE, num_conv, (UG(to_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC);
-               retval = FALSE;
+               if (u) {
+                       efree(u);
+               }
+               ZVAL_EMPTY_UNICODE(string);
+               efree(s);
+               return FAILURE;
+       } else {
+               ZVAL_UNICODEL(string, u, u_len, 0);
+               efree(s);
+               return SUCCESS;
        }
-
-       ZVAL_UNICODEL(string, u, u_len, 0);
-
-       efree(s);
-       return retval;
 }
 /* }}} */