Fixed minor memory leak.
[pspp-builds.git] / src / libpspp / i18n.c
index bcac52cf58b35b062aa6a45503887d84cc68c780..360c9abd3145ca6cc64a66996bfe309d164fa624 100644 (file)
@@ -54,6 +54,9 @@ recode_string(enum conv_id how,  const char *text, int length)
   /* FIXME: Need to ensure that this char is valid in the target encoding */
   const char fallbackchar = '?';
 
+  if ( text == NULL ) 
+    return NULL;
+
   if ( length == -1 ) 
      length = strlen(text);
 
@@ -71,8 +74,6 @@ recode_string(enum conv_id how,  const char *text, int length)
   inbytes = length;
   
   do {
-
-  
     result = iconv(convertor[how], &ip, &inbytes, 
                   &op, &outbytes);
 
@@ -108,11 +109,17 @@ recode_string(enum conv_id how,  const char *text, int length)
          }
 
       }
-
   } while ( -1 == result );
 
+  if (outbytes == 0 ) 
+    {
+      char *const oldaddr = outbuf;
+      outbuf = xrealloc(outbuf, outbufferlength + 1);
+      
+      op += (outbuf - oldaddr) ;
+    }
+
   *op = '\0';
-  
 
   return outbuf;
 }