From: Pierangelo Masarati Date: Thu, 16 Aug 2007 12:08:47 +0000 (+0000) Subject: consistently use SLAP_* malloc macros; alloc sizeof(Syntax *) instead of sizeof(Synta... X-Git-Tag: OPENLDAP_REL_ENG_2_4_MP~202 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=51152d83a3b6818cba72a859070790a0e2f065e4;p=openldap consistently use SLAP_* malloc macros; alloc sizeof(Syntax *) instead of sizeof(Syntax) for areray of superiors; free resources also in case of failure of syn_insert() --- diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index 8faffad041..249f3681d9 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -196,14 +196,19 @@ syn_add( for ( cnt = 0; def->sd_sups[cnt] != NULL; cnt++ ) ; - ssyn->ssyn_sups = (Syntax **)ch_calloc( cnt + 1, - sizeof(Syntax) ); - - for ( cnt = 0; def->sd_sups[cnt] != NULL; cnt++ ) { - ssyn->ssyn_sups[cnt] = syn_find( def->sd_sups[cnt] ); - if ( ssyn->ssyn_sups[cnt] == NULL ) { - *err = def->sd_sups[cnt]; - code = SLAP_SCHERR_SYN_SUP_NOT_FOUND; + ssyn->ssyn_sups = (Syntax **)SLAP_CALLOC( cnt + 1, + sizeof( Syntax * ) ); + if ( ssyn->ssyn_sups == NULL ) { + Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 ); + code = SLAP_SCHERR_OUTOFMEM; + + } else { + for ( cnt = 0; def->sd_sups[cnt] != NULL; cnt++ ) { + ssyn->ssyn_sups[cnt] = syn_find( def->sd_sups[cnt] ); + if ( ssyn->ssyn_sups[cnt] == NULL ) { + *err = def->sd_sups[cnt]; + code = SLAP_SCHERR_SYN_SUP_NOT_FOUND; + } } } } @@ -211,9 +216,11 @@ syn_add( if ( code == 0 ) { code = syn_insert( ssyn, err ); - } else if ( ssyn != NULL ) { + } + + if ( code != 0 && ssyn != NULL ) { if ( ssyn->ssyn_sups != NULL ) { - ch_free( ssyn->ssyn_sups ); + SLAP_FREE( ssyn->ssyn_sups ); } SLAP_FREE( ssyn ); }