Fix cargv leak in recursive read_config()

This commit is contained in:
Howard Chu 2002-08-07 08:22:43 +00:00
parent 4a4323e3b7
commit 554311a4c8
4 changed files with 11 additions and 7 deletions

View File

@ -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 );
}

View File

@ -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 );

View File

@ -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));
/*

View File

@ -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 );