ITS#6145 free/close before exit

This commit is contained in:
Howard Chu 2009-07-22 07:19:41 +00:00
parent e0bcb7b571
commit 048f24150f
2 changed files with 94 additions and 77 deletions

View File

@ -162,12 +162,10 @@ int
main( int argc, char **argv )
{
char buf[ 4096 ];
FILE *fp;
FILE *fp = NULL;
LDAP *ld;
int rc, retval;
fp = NULL;
tool_init( TOOL_DELETE );
prog = lutil_progname( "ldapdelete", argc, argv );
@ -189,7 +187,11 @@ main( int argc, char **argv )
if ( pw_file || want_bindpw ) {
if ( pw_file ) {
rc = lutil_get_filed_password( pw_file, &passwd );
if( rc ) return EXIT_FAILURE;
if( rc ) {
if ( fp && fp != stdin )
fclose( fp );
return EXIT_FAILURE;
}
} else {
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
@ -222,6 +224,8 @@ main( int argc, char **argv )
retval = rc;
}
}
if ( fp != stdin )
fclose( fp );
}
tool_unbind( ld );

View File

@ -151,7 +151,7 @@ int
main(int argc, char **argv)
{
char *entrydn = NULL, *rdn = NULL, buf[ 4096 ];
FILE *fp;
FILE *fp = NULL;
LDAP *ld;
int rc, retval, havedn;
@ -164,11 +164,13 @@ main(int argc, char **argv)
if (argc - optind == 2) {
if (( rdn = strdup( argv[argc - 1] )) == NULL ) {
perror( "strdup" );
return( EXIT_FAILURE );
retval = EXIT_FAILURE;
goto fail;
}
if (( entrydn = strdup( argv[argc - 2] )) == NULL ) {
perror( "strdup" );
return( EXIT_FAILURE );
retval = EXIT_FAILURE;
goto fail;
}
++havedn;
} else if ( argc - optind != 0 ) {
@ -179,7 +181,8 @@ main(int argc, char **argv)
if ( infile != NULL ) {
if (( fp = fopen( infile, "r" )) == NULL ) {
perror( infile );
return( EXIT_FAILURE );
retval = EXIT_FAILURE;
goto fail;
}
} else {
fp = stdin;
@ -190,7 +193,10 @@ main(int argc, char **argv)
if ( pw_file || want_bindpw ) {
if ( pw_file ) {
rc = lutil_get_filed_password( pw_file, &passwd );
if( rc ) return EXIT_FAILURE;
if( rc ) {
retval = EXIT_FAILURE;
goto fail;
}
} else {
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
@ -211,16 +217,19 @@ main(int argc, char **argv)
if ( havedn ) { /* have DN, get RDN */
if (( rdn = strdup( buf )) == NULL ) {
perror( "strdup" );
return( EXIT_FAILURE );
retval = EXIT_FAILURE;
goto fail;
}
rc = domodrdn(ld, entrydn, rdn, newSuperior, remove_old_RDN );
if ( rc != 0 )
retval = rc;
havedn = 0;
free( rdn ); rdn = NULL;
free( entrydn ); entrydn = NULL;
} else if ( !havedn ) { /* don't have DN yet */
if (( entrydn = strdup( buf )) == NULL ) {
perror( "strdup" );
return( EXIT_FAILURE );
retval = EXIT_FAILURE;
goto fail;
}
++havedn;
}
@ -229,6 +238,10 @@ main(int argc, char **argv)
tool_unbind( ld );
tool_destroy();
fail:
if ( fp && fp != stdin ) fclose( fp );
if ( entrydn ) free( entrydn );
if ( rdn ) free( rdn );
return( retval );
}