Fix potential memory leak in console.c

CAUTION: untested as my openssl installation has gone insane.

If the incoming "hScreen" parameter is NULL, a new PSCREEN_RECORD is
allocated to use in its place.
However, if the allocation of the "pScreenBuf" member variable fails,
the function returns, potentially leaking the newly allocated
PSCREEN_RECORD.

This fix first checks to see if the functions owns the "pScreenRec", and
if so, frees it before returning.
This commit is contained in:
Dirk de la Hunt 2015-10-22 20:04:14 +02:00
parent 89452c8a2f
commit 5d455454de

View File

@ -1608,7 +1608,13 @@ SCREEN_HANDLE ConSaveScreenHandle( SCREEN_HANDLE hScreen )
}
if ( !pScreenRec->pScreenBuf )
{
// if we allocated a screen within this scope, free it before returning
if ( pScreenRec != (PSCREEN_RECORD)hScreen ) {
free(pScreenRec);
}
return NULL;
}
result = ReadConsoleOutput( hConsole, // handle of a console screen buffer
(PCHAR_INFO)(pScreenRec->pScreenBuf), // address of buffer that receives data