From 8aa34fd4491279d0b48eaca357724fb5d26b5071 Mon Sep 17 00:00:00 2001 From: Michael Ow Date: Wed, 3 Oct 2012 03:32:21 +0000 Subject: [PATCH] ICU-9581 Fix some memory leaks in arabic shaping code X-SVN-Rev: 32491 --- icu4c/source/common/ushape.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/icu4c/source/common/ushape.cpp b/icu4c/source/common/ushape.cpp index 1466d1f7877..bad853167ff 100644 --- a/icu4c/source/common/ushape.cpp +++ b/icu4c/source/common/ushape.cpp @@ -724,14 +724,15 @@ handleGeneratedSpaces(UChar *dest, int32_t sourceLength, } } - if (lamAlefOption || tashkeelOption){ - tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); - /* Test for NULL */ - if(tempbuffer == NULL) { - *pErrorCode = U_MEMORY_ALLOCATION_ERROR; - return 0; - } + tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); + /* Test for NULL */ + if(tempbuffer == NULL) { + *pErrorCode = U_MEMORY_ALLOCATION_ERROR; + return 0; + } + + if (lamAlefOption || tashkeelOption){ uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); i = j = 0; count = 0; @@ -791,16 +792,10 @@ handleGeneratedSpaces(UChar *dest, int32_t sourceLength, } if(lamAlefOption || tashkeelOption){ - tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); - - /* Test for NULL */ - if(tempbuffer == NULL) { - *pErrorCode = U_MEMORY_ALLOCATION_ERROR; - return 0; - } - uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); + i = j = sourceLength; count = 0; + while(i >= 0) { if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) || (tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){ @@ -838,13 +833,6 @@ handleGeneratedSpaces(UChar *dest, int32_t sourceLength, } if(lamAlefOption || tashkeelOption){ - tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR); - /* Test for NULL */ - if(tempbuffer == NULL) { - *pErrorCode = U_MEMORY_ALLOCATION_ERROR; - return 0; - } - uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR); i = j = 0; count = 0;