msvcrt: Don't crash on NULL in fclose.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2021-10-11 16:15:32 +02:00 committed by Alexandre Julliard
parent 776c840aa5
commit bb637469e1
2 changed files with 7 additions and 0 deletions

View File

@ -3616,6 +3616,8 @@ int CDECL fclose(FILE* file)
{
int ret;
if (!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
_lock_file(file);
ret = _fclose_nolock(file);
_unlock_file(file);
@ -3630,6 +3632,8 @@ int CDECL _fclose_nolock(FILE* file)
{
int r, flag;
if (!MSVCRT_CHECK_PMT(file != NULL)) return EOF;
if(!(file->_flag & (_IOREAD | _IOWRT | _IORW)))
{
file->_flag = 0;

View File

@ -1878,6 +1878,9 @@ static void test_fopen_fclose_fcloseall( void )
ret = fclose(stream3);
ok(ret == EOF, "Closing file '%s' returned %d\n", fname3, ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ret = fclose(NULL);
ok(ret == EOF, "Closing NULL file returned %d\n", ret);
ok(errno = EINVAL, "errno = %d\n", errno);
/* testing fcloseall() */
numclosed = _fcloseall();