[0.4.13][GDI32][BUTTERFLIES] Fix a BSOD caused by memory leak CORE-18498

The symptom was unhidden by (regression from users perspective):
0.4.12-dev-389-g 5f2bebf7a5

by porting back:
0.4.15-dev-5608-g afb953ae4d [BUTTERFLIES] Do not release the DC passed to OpenGL. CORE-18498
0.4.15-dev-5607-g 8b19b6ec5a [GDI32] Fix memory leak in case of public DC. CORE-18498

For now I will not port it back further than releases/0.4.12
although the code in both modules might be suboptimal even in earlier release-branches.
But we see no symptoms in those yet.
This commit is contained in:
Joachim Henze 2023-02-09 16:34:12 +01:00
parent f28daad01b
commit 69674a1e9d
2 changed files with 10 additions and 6 deletions

View file

@ -12,6 +12,7 @@
HINSTANCE hInstance; // Holds The Instance Of The Application
GLuint texture[3]; //stores texture objects and display list
HDC hdcOpenGL;
LPCTSTR registryPath = _T("Software\\Microsoft\\ScreenSavers\\Butterflies");
BOOL dRotate;
@ -136,7 +137,7 @@ HGLRC InitOGLWindow(HWND hWnd)
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
ReleaseDC(hWnd, hDC);
hdcOpenGL = hDC;
return hRC;
}
@ -231,7 +232,7 @@ void Display()
}
INT_PTR CALLBACK AboutProc(HWND hdlg, UINT msg, WPARAM wpm, LPARAM lpm){
switch(msg){
case WM_CTLCOLORSTATIC:
if(((HWND)lpm == GetDlgItem(hdlg, WEBPAGE1)) || ((HWND)lpm == GetDlgItem(hdlg, WEBPAGE2)))
@ -287,6 +288,7 @@ LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message,
case WM_DESTROY:
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hdcOpenGL);
break;
}

View file

@ -755,7 +755,8 @@ SetDIBitsToDevice(
if (!GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID) & pDc_Attr))
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
LinesCopied = 0;
goto Exit;
}
/*
if ( !pDc_Attr || // DC is Public
@ -858,8 +859,7 @@ StretchDIBits(
if ( GdiConvertAndCheckDC(hdc) == NULL ) return 0;
pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage, &ConvertedInfoSize,
FALSE);
pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage, &ConvertedInfoSize, FALSE);
if (!pConvertedInfo)
{
return 0;
@ -896,7 +896,8 @@ StretchDIBits(
if (!GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID) & pDc_Attr))
{
SetLastError(ERROR_INVALID_PARAMETER);
return 0;
LinesCopied = 0;
goto Exit;
}
/*
if ( !pDc_Attr ||
@ -910,6 +911,7 @@ StretchDIBits(
ConvertedInfoSize, cjBmpScanSize,
NULL);
}
Exit:
if (pvSafeBits)
RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
if (lpBitsInfo != pConvertedInfo)