]> git.sur5r.net Git - openldap/commitdiff
Plug memory leak (ITS#2126)
authorKurt Zeilenga <kurt@openldap.org>
Tue, 8 Oct 2002 19:45:01 +0000 (19:45 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 8 Oct 2002 19:45:01 +0000 (19:45 +0000)
libraries/liblunicode/ucstr.c

index bc46a951699f1ff35eae6230f28e352de4f95b72..69fce783f8efc4f0646b715460ce3ec7864b5094 100644 (file)
@@ -98,7 +98,7 @@ struct berval * UTF8bvnormalize(
        unsigned flags )
 {
        int i, j, len, clen, outpos, ucsoutlen, outsize, last;
-       char *out, *s;
+       char *out, *outtmp, *s;
        unsigned long *ucs, *p, *ucsout;
 
        unsigned casefold = flags & LDAP_UTF8_CASEFOLD;
@@ -227,15 +227,21 @@ struct berval * UTF8bvnormalize(
                                   6 bytes and terminator */
                                if ( outsize - outpos < 7 ) {
                                        outsize = ucsoutlen - j + outpos + 6;
-                                       out = (char *) realloc( out, outsize );
-                                       if ( out == NULL ) {
+                                       outtmp = (char *) realloc( out, outsize );
+                                       if ( outtmp == NULL ) {
+                                               free( out );
                                                free( ucs );
+                                               free( ucsout );
                                                return NULL;
                                        }
+                                       out = outtmp;
                                }
                                outpos += ldap_x_ucs4_to_utf8( ucsout[j], &out[outpos] );
                        }
                }
+
+               free( ucsout );
+               ucsout = NULL;
                
                if ( i == len ) {
                        break;