Author: cwittich Date: Sat Sep 20 04:28:55 2008 New Revision: 36342
URL: http://svn.reactos.org/svn/reactos?rev=36342&view=rev Log: fix some resource leaks
Modified: trunk/reactos/base/applications/mstsc/connectdialog.c
Modified: trunk/reactos/base/applications/mstsc/connectdialog.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mstsc/con... ============================================================================== --- trunk/reactos/base/applications/mstsc/connectdialog.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/mstsc/connectdialog.c [iso-8859-1] Sat Sep 20 04:28:55 2008 @@ -163,6 +163,7 @@
i++; } + RegCloseKey(hKey); }
if (LoadStringW(hInst, @@ -851,10 +852,11 @@ if(lpDrawItem->CtlID == IDC_COLORIMAGE) { HDC hdcMem; + HBITMAP hSpecOld; hdcMem = CreateCompatibleDC(lpDrawItem->hDC); if (hdcMem != NULL) { - SelectObject(hdcMem, pInfo->hSpectrum); + hSpecOld = SelectObject(hdcMem, pInfo->hSpectrum); StretchBlt(lpDrawItem->hDC, lpDrawItem->rcItem.left, lpDrawItem->rcItem.top, @@ -866,6 +868,7 @@ pInfo->bitmap.bmWidth, pInfo->bitmap.bmHeight, SRCCOPY); + SelectObject(hdcMem, hSpecOld); DeleteDC(hdcMem); } } @@ -1020,6 +1023,31 @@ 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 DlgProc(HWND hDlg, @@ -1052,14 +1080,7 @@ SaveAllSettings(pInfo); SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings); } - - if (pInfo) - { - HeapFree(GetProcessHeap(), - 0, - pInfo); - } - + Cleanup(pInfo); EndDialog(hDlg, LOWORD(wParam)); }
@@ -1096,11 +1117,12 @@ WCHAR szBuffer[32]; RECT bmpRc, txtRc; LOGFONTW lf; - HFONT hFont; + HFONT hFont, hFontOld; + HBITMAP hBmpOld;
GetClientRect(pInfo->hSelf, &bmpRc);
- SelectObject(hdcMem, pInfo->hHeader); + hBmpOld = SelectObject(hdcMem, pInfo->hHeader); StretchBlt(hdc, 0, 0, @@ -1113,6 +1135,7 @@ pInfo->headerbitmap.bmHeight, SRCCOPY);
+ SelectObject(hdcMem, hBmpOld); txtRc.left = bmpRc.right * 0.25; txtRc.top = 10; txtRc.right = bmpRc.right * 0.75; @@ -1134,7 +1157,7 @@ hFont = CreateFontIndirectW(&lf); if (hFont) { - SelectObject(hdc, hFont); + hFontOld = SelectObject(hdc, hFont);
DPtoLP(hdc, (PPOINT)&txtRc, 2); SetTextColor(hdc, RGB(255,255,255)); @@ -1144,6 +1167,7 @@ -1, &txtRc, DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP); + SelectObject(hdc, hFontOld); DeleteObject(hFont); } } @@ -1167,7 +1191,7 @@ hFont = CreateFontIndirectW(&lf); if (hFont) { - SelectObject(hdc, hFont); + hFontOld = SelectObject(hdc, hFont);
DPtoLP(hdc, (PPOINT)&txtRc, 2); SetTextColor(hdc, RGB(255,255,255)); @@ -1177,6 +1201,8 @@ -1, &txtRc, DT_TOP | DT_SINGLELINE); + SelectObject(hdc, hFontOld); + DeleteObject(hFont); } }
@@ -1191,20 +1217,7 @@
case WM_CLOSE: { - if (pInfo) - { - if (pInfo->hMstscSm) - DestroyIcon(pInfo->hMstscSm); - if (pInfo->hMstscLg) - DestroyIcon(pInfo->hMstscLg); - if (pInfo->hHeader) - DeleteObject(pInfo->hHeader); - - HeapFree(GetProcessHeap(), - 0, - pInfo); - } - + Cleanup(pInfo); EndDialog(hDlg, 0); } break;