fix some resource leaks

svn path=/trunk/; revision=36342
This commit is contained in:
Christoph von Wittich 2008-09-20 09:28:55 +00:00
parent 1e89fe22e0
commit 2aa6b99347

View file

@ -163,6 +163,7 @@ FillServerAddesssCombo(PINFO pInfo)
i++; i++;
} }
RegCloseKey(hKey);
} }
if (LoadStringW(hInst, if (LoadStringW(hInst,
@ -851,10 +852,11 @@ DisplayDlgProc(HWND hDlg,
if(lpDrawItem->CtlID == IDC_COLORIMAGE) if(lpDrawItem->CtlID == IDC_COLORIMAGE)
{ {
HDC hdcMem; HDC hdcMem;
HBITMAP hSpecOld;
hdcMem = CreateCompatibleDC(lpDrawItem->hDC); hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
if (hdcMem != NULL) if (hdcMem != NULL)
{ {
SelectObject(hdcMem, pInfo->hSpectrum); hSpecOld = SelectObject(hdcMem, pInfo->hSpectrum);
StretchBlt(lpDrawItem->hDC, StretchBlt(lpDrawItem->hDC,
lpDrawItem->rcItem.left, lpDrawItem->rcItem.left,
lpDrawItem->rcItem.top, lpDrawItem->rcItem.top,
@ -866,6 +868,7 @@ DisplayDlgProc(HWND hDlg,
pInfo->bitmap.bmWidth, pInfo->bitmap.bmWidth,
pInfo->bitmap.bmHeight, pInfo->bitmap.bmHeight,
SRCCOPY); SRCCOPY);
SelectObject(hdcMem, hSpecOld);
DeleteDC(hdcMem); DeleteDC(hdcMem);
} }
} }
@ -1020,6 +1023,31 @@ OnMainCreate(HWND hwnd,
return bRet; return bRet;
} }
static void Cleanup(PINFO pInfo)
{
if (pInfo)
{
if (pInfo->hMstscSm)
DestroyIcon(pInfo->hMstscSm);
if (pInfo->hMstscLg)
DestroyIcon(pInfo->hMstscLg);
if (pInfo->hHeader)
DeleteObject(pInfo->hHeader);
if (pInfo->hSpectrum)
DeleteObject(pInfo->hSpectrum);
if (pInfo->hRemote)
DestroyIcon(pInfo->hRemote);
if (pInfo->hLogon)
DestroyIcon(pInfo->hLogon);
if (pInfo->hConn)
DestroyIcon(pInfo->hConn);
if (pInfo->hColor)
DestroyIcon(pInfo->hColor);
HeapFree(GetProcessHeap(),
0,
pInfo);
}
}
static BOOL CALLBACK static BOOL CALLBACK
DlgProc(HWND hDlg, DlgProc(HWND hDlg,
@ -1052,14 +1080,7 @@ DlgProc(HWND hDlg,
SaveAllSettings(pInfo); SaveAllSettings(pInfo);
SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings); SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings);
} }
Cleanup(pInfo);
if (pInfo)
{
HeapFree(GetProcessHeap(),
0,
pInfo);
}
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
} }
@ -1096,11 +1117,12 @@ DlgProc(HWND hDlg,
WCHAR szBuffer[32]; WCHAR szBuffer[32];
RECT bmpRc, txtRc; RECT bmpRc, txtRc;
LOGFONTW lf; LOGFONTW lf;
HFONT hFont; HFONT hFont, hFontOld;
HBITMAP hBmpOld;
GetClientRect(pInfo->hSelf, &bmpRc); GetClientRect(pInfo->hSelf, &bmpRc);
SelectObject(hdcMem, pInfo->hHeader); hBmpOld = SelectObject(hdcMem, pInfo->hHeader);
StretchBlt(hdc, StretchBlt(hdc,
0, 0,
0, 0,
@ -1113,6 +1135,7 @@ DlgProc(HWND hDlg,
pInfo->headerbitmap.bmHeight, pInfo->headerbitmap.bmHeight,
SRCCOPY); SRCCOPY);
SelectObject(hdcMem, hBmpOld);
txtRc.left = bmpRc.right * 0.25; txtRc.left = bmpRc.right * 0.25;
txtRc.top = 10; txtRc.top = 10;
txtRc.right = bmpRc.right * 0.75; txtRc.right = bmpRc.right * 0.75;
@ -1134,7 +1157,7 @@ DlgProc(HWND hDlg,
hFont = CreateFontIndirectW(&lf); hFont = CreateFontIndirectW(&lf);
if (hFont) if (hFont)
{ {
SelectObject(hdc, hFont); hFontOld = SelectObject(hdc, hFont);
DPtoLP(hdc, (PPOINT)&txtRc, 2); DPtoLP(hdc, (PPOINT)&txtRc, 2);
SetTextColor(hdc, RGB(255,255,255)); SetTextColor(hdc, RGB(255,255,255));
@ -1144,6 +1167,7 @@ DlgProc(HWND hDlg,
-1, -1,
&txtRc, &txtRc,
DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP); DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP);
SelectObject(hdc, hFontOld);
DeleteObject(hFont); DeleteObject(hFont);
} }
} }
@ -1167,7 +1191,7 @@ DlgProc(HWND hDlg,
hFont = CreateFontIndirectW(&lf); hFont = CreateFontIndirectW(&lf);
if (hFont) if (hFont)
{ {
SelectObject(hdc, hFont); hFontOld = SelectObject(hdc, hFont);
DPtoLP(hdc, (PPOINT)&txtRc, 2); DPtoLP(hdc, (PPOINT)&txtRc, 2);
SetTextColor(hdc, RGB(255,255,255)); SetTextColor(hdc, RGB(255,255,255));
@ -1177,6 +1201,8 @@ DlgProc(HWND hDlg,
-1, -1,
&txtRc, &txtRc,
DT_TOP | DT_SINGLELINE); DT_TOP | DT_SINGLELINE);
SelectObject(hdc, hFontOld);
DeleteObject(hFont);
} }
} }
@ -1191,20 +1217,7 @@ DlgProc(HWND hDlg,
case WM_CLOSE: case WM_CLOSE:
{ {
if (pInfo) Cleanup(pInfo);
{
if (pInfo->hMstscSm)
DestroyIcon(pInfo->hMstscSm);
if (pInfo->hMstscLg)
DestroyIcon(pInfo->hMstscLg);
if (pInfo->hHeader)
DeleteObject(pInfo->hHeader);
HeapFree(GetProcessHeap(),
0,
pInfo);
}
EndDialog(hDlg, 0); EndDialog(hDlg, 0);
} }
break; break;