[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 HINSTANCE hInstance; // Holds The Instance Of The Application
GLuint texture[3]; //stores texture objects and display list GLuint texture[3]; //stores texture objects and display list
HDC hdcOpenGL;
LPCTSTR registryPath = _T("Software\\Microsoft\\ScreenSavers\\Butterflies"); LPCTSTR registryPath = _T("Software\\Microsoft\\ScreenSavers\\Butterflies");
BOOL dRotate; BOOL dRotate;
@ -136,7 +137,7 @@ HGLRC InitOGLWindow(HWND hWnd)
hRC = wglCreateContext(hDC); hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC); wglMakeCurrent(hDC, hRC);
ReleaseDC(hWnd, hDC); hdcOpenGL = hDC;
return hRC; return hRC;
} }
@ -287,6 +288,7 @@ LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message,
case WM_DESTROY: case WM_DESTROY:
wglMakeCurrent(NULL, NULL); wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC); wglDeleteContext(hRC);
ReleaseDC(hWnd, hdcOpenGL);
break; break;
} }

View file

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