]> git.sur5r.net Git - openldap/blobdiff - clients/tools/ldapdelete.c
ITS#6145 free/close before exit
[openldap] / clients / tools / ldapdelete.c
index 5424758a6321aa8ee53fc97c3b3d4922d71a1469..61c78408f7a5b47d2411a9bf5f5233dcd2b68ee2 100644 (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 );
 
@@ -179,9 +177,9 @@ main( int argc, char **argv )
                        exit( EXIT_FAILURE );
            }
        } else {
-       if ( optind >= argc ) {
-           fp = stdin;
-       }
+               if ( optind >= argc ) {
+                       fp = stdin;
+               }
     }
 
        ld = tool_conn_setup( 0, &private_conn_setup );
@@ -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 );