From 60510c5e399a3144f60cf3fe0be871d1f249c29d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 29 Dec 2001 06:37:20 +0000 Subject: [PATCH] Fix memory leak in ldap_explode_dn --- libraries/libldap/getdn.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/libraries/libldap/getdn.c b/libraries/libldap/getdn.c index d45a2321a4..655b711e20 100644 --- a/libraries/libldap/getdn.c +++ b/libraries/libldap/getdn.c @@ -151,22 +151,20 @@ ldap_explode_dn( LDAP_CONST char *dn, int notypes ) return values; } - for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) { - char *str, **v = NULL; - - ldap_rdn2str( tmpDN[ iRDN ][ 0 ], &str, flag ); + for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ); - v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iRDN ) ); - if ( v == NULL ) { - LBER_VFREE( values ); - ldap_dnfree( tmpDN ); - return NULL; - } - values = v; - values[ iRDN ] = str; + values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iRDN ) ); + if ( values == NULL ) { + ldap_dnfree( tmpDN ); + return NULL; } + for ( iRDN = 0; tmpDN[ iRDN ]; iRDN++ ) { + ldap_rdn2str( tmpDN[ iRDN ][ 0 ], &values[ iRDN ], flag ); + } + ldap_dnfree( tmpDN ); values[ iRDN ] = NULL; + return values; } @@ -190,17 +188,18 @@ ldap_explode_rdn( LDAP_CONST char *rdn, int notypes ) return( NULL ); } + for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) ; + values = LDAP_MALLOC( sizeof( char * ) * ( 1 + iAVA ) ); + if ( values == NULL ) { + ldap_rdnfree( tmpRDN ); + return( NULL ); + } + for ( iAVA = 0; tmpRDN[ iAVA ]; iAVA++ ) { ber_len_t l = 0, vl, al = 0; - char *str, **v = NULL; + char *str; LDAPAVA *ava = tmpRDN[ iAVA ][ 0 ]; - v = LDAP_REALLOC( values, sizeof( char * ) * ( 2 + iAVA ) ); - if ( v == NULL ) { - goto error_return; - } - values = v; - if ( ava->la_flags == LDAP_AVA_BINARY ) { vl = 1 + 2 * ava->la_value->bv_len; -- 2.39.5