]> granicus.if.org Git - icu/commitdiff
ICU-9581 Fix some memory leaks in arabic shaping code
authorMichael Ow <mow@svn.icu-project.org>
Wed, 3 Oct 2012 03:32:21 +0000 (03:32 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Wed, 3 Oct 2012 03:32:21 +0000 (03:32 +0000)
X-SVN-Rev: 32491

icu4c/source/common/ushape.cpp

index 1466d1f78773f53b950a2f9f997013f62712f029..bad853167ffeab26d05ca92fcfede05d6af4d561 100644 (file)
@@ -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;