From: Howard Chu Date: Wed, 7 Aug 2002 08:22:43 +0000 (+0000) Subject: Fix cargv leak in recursive read_config() X-Git-Tag: NO_SLAP_OP_BLOCKS~1262 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=554311a4c88a847f9f65055af72b5a761b5b8a49;p=openldap Fix cargv leak in recursive read_config() --- diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 5362cbdb9e..0046551709 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -75,7 +75,7 @@ static char *strtok_quote(char *line, char *sep); static int load_ucdata(char *path); int -read_config( const char *fname ) +read_config( const char *fname, int depth ) { FILE *fp; char *line, *savefname, *saveline; @@ -90,8 +90,10 @@ read_config( const char *fname ) vals[1].bv_val = NULL; - cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) ); - cargv_size = ARGS_STEP + 1; + if ( depth == 0 ) { + cargv = ch_calloc( ARGS_STEP + 1, sizeof(*cargv) ); + cargv_size = ARGS_STEP + 1; + } if ( (fp = fopen( fname, "r" )) == NULL ) { ldap_syslog = 1; @@ -2012,7 +2014,7 @@ read_config( const char *fname ) savefname = ch_strdup( cargv[1] ); savelineno = lineno; - if ( read_config( savefname ) != 0 ) { + if ( read_config( savefname, depth+1 ) != 0 ) { return( 1 ); } @@ -2257,6 +2259,8 @@ read_config( const char *fname ) } fclose( fp ); + if ( depth == 0 ) ch_free( cargv ); + if ( load_ucdata( NULL ) < 0 ) return 1; return( 0 ); } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index de931e4908..8a40fe52a7 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -405,7 +405,7 @@ int main( int argc, char **argv ) (void) ldap_pvt_tls_set_option( NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc ); #endif - if ( read_config( configfile ) != 0 ) { + if ( read_config( configfile, 0 ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 583b09e5b1..cb65f3fb92 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -280,7 +280,7 @@ LDAP_SLAPD_F (char *) get_supported_ctrl LDAP_P((int index)); /* * config.c */ -LDAP_SLAPD_F (int) read_config LDAP_P(( const char *fname )); +LDAP_SLAPD_F (int) read_config LDAP_P(( const char *fname, int depth )); LDAP_SLAPD_F (void) config_destroy LDAP_P ((void)); /* diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index abe5b7abeb..27c6712724 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -195,7 +195,7 @@ slap_tool_init( exit( EXIT_FAILURE ); } - rc = read_config( conffile ); + rc = read_config( conffile, 0 ); if ( rc != 0 ) { fprintf( stderr, "%s: bad configuration file!\n", progname );