Skip to content

Commit 5d45545

Browse files
author
Dirk de la Hunt
committed
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.
1 parent 89452c8 commit 5d45545

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

contrib/win32/win32compat/console.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,13 @@ SCREEN_HANDLE ConSaveScreenHandle( SCREEN_HANDLE hScreen )
16081608
}
16091609

16101610
if ( !pScreenRec->pScreenBuf )
1611+
{
1612+
// if we allocated a screen within this scope, free it before returning
1613+
if ( pScreenRec != (PSCREEN_RECORD)hScreen ) {
1614+
free(pScreenRec);
1615+
}
16111616
return NULL;
1617+
}
16121618

16131619
result = ReadConsoleOutput( hConsole, // handle of a console screen buffer
16141620
(PCHAR_INFO)(pScreenRec->pScreenBuf), // address of buffer that receives data

0 commit comments

Comments
 (0)