unix/password: Fix file descriptor leak.

Found by: Coverity scan.
This commit is contained in:
Vladimir Serbinenko 2015-01-26 09:53:03 +01:00
parent cba5a85a67
commit 8102540939

View file

@ -53,7 +53,10 @@ grub_password_get (char buf[], unsigned buf_size)
tty_changed = 0;
grub_memset (buf, 0, buf_size);
if (!fgets (buf, buf_size, stdin))
{
fclose (in);
return 0;
}
ptr = buf + strlen (buf) - 1;
while (buf <= ptr && (*ptr == '\n' || *ptr == '\r'))
*ptr-- = 0;
@ -64,5 +67,7 @@ grub_password_get (char buf[], unsigned buf_size)
grub_xputs ("\n");
grub_refresh ();
fclose (in);
return 1;
}