File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ pub fn terminal_size(out: &Term) -> Option<(u16, u16)> {
6767}
6868
6969pub fn read_secure ( ) -> io:: Result < String > {
70- let f_tty;
70+ let mut f_tty;
7171 let fd = unsafe {
7272 if libc:: isatty ( libc:: STDIN_FILENO ) == 1 {
7373 f_tty = None ;
@@ -91,14 +91,17 @@ pub fn read_secure() -> io::Result<String> {
9191 c_result ( || unsafe { libc:: tcsetattr ( fd, libc:: TCSAFLUSH , & termios) } ) ?;
9292 let mut rv = String :: new ( ) ;
9393
94- let read_rv = if let Some ( mut f) = f_tty {
94+ let read_rv = if let Some ( f) = & mut f_tty {
9595 f. read_line ( & mut rv)
9696 } else {
9797 io:: stdin ( ) . read_line ( & mut rv)
9898 } ;
9999
100100 c_result ( || unsafe { libc:: tcsetattr ( fd, libc:: TCSAFLUSH , & original) } ) ?;
101101
102+ // Ensure the fd is only closed after everything has been restored.
103+ drop ( f_tty) ;
104+
102105 read_rv. map ( |_| {
103106 let len = rv. trim_end_matches ( & [ '\r' , '\n' ] [ ..] ) . len ( ) ;
104107 rv. truncate ( len) ;
You can’t perform that action at this time.
0 commit comments