Skip to content

Commit cd2d284

Browse files
committed
[EXPLORER][BROWSEUI][SHELL32][NETSHELL] Fix wrong usage of CComPtr
1 parent a414c88 commit cd2d284

File tree

13 files changed

+23
-41
lines changed

13 files changed

+23
-41
lines changed

base/shell/explorer/startctxmnu.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,5 @@ class CStartMenuBtnCtxMenu :
242242

243243
HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu)
244244
{
245-
CStartMenuBtnCtxMenu * mnu = new CComObject<CStartMenuBtnCtxMenu>();
246-
mnu->Initialize(m_TrayWnd, m_Owner);
247-
*ppCtxMenu = mnu;
248-
return S_OK;
245+
return ShellObjectCreatorInit<CStartMenuBtnCtxMenu>(m_TrayWnd, m_Owner, IID_PPV_ARG(IContextMenu, ppCtxMenu));
249246
}

base/shell/explorer/tbsite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ class CTrayBandSite :
301301

302302
if (ppcm != NULL)
303303
{
304-
m_ContextMenu->AddRef();
305304
*ppcm = m_ContextMenu;
305+
(*ppcm)->AddRef();
306306
}
307307

308308
/* Add the menu items */

base/shell/explorer/traywnd.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,6 @@ class CTrayWindow :
29432943
{
29442944
CComPtr<IContextMenu> ctxMenu;
29452945
CStartMenuBtnCtxMenu_CreateInstance(this, m_hWnd, &ctxMenu);
2946-
ctxMenu->AddRef();
29472946
TrackCtxMenu(ctxMenu, ppt, hWndExclude, m_Position == ABE_BOTTOM, this);
29482947
}
29492948
}

dll/shellext/netshell/lanstatusui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ CLanStatus::InitializeNetTaskbarNotifications()
953953
pItem->uID = Index;
954954
pItem->pNext = NULL;
955955
pItem->pNet = pNetCon;
956-
pNetCon->AddRef();
956+
pItem->pNet->AddRef();
957957
hwndDlg = CreateDialogParamW(netshell_hInstance, MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext);
958958
if (!hwndDlg)
959959
{

dll/win32/browseui/CAutoComplete.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,18 +1126,12 @@ CAutoComplete::Init(HWND hwndEdit, IUnknown *punkACL,
11261126
::GetWindowRect(m_hwndEdit, &m_rcEdit);
11271127

11281128
// get an IEnumString
1129-
ATLASSERT(!m_pEnum);
11301129
punkACL->QueryInterface(IID_IEnumString, (VOID **)&m_pEnum);
11311130
TRACE("m_pEnum: %p\n", static_cast<void *>(m_pEnum));
1132-
if (m_pEnum)
1133-
m_pEnum->AddRef(); // hold not to be freed
11341131

11351132
// get an IACList
1136-
ATLASSERT(!m_pACList);
11371133
punkACL->QueryInterface(IID_IACList, (VOID **)&m_pACList);
11381134
TRACE("m_pACList: %p\n", static_cast<void *>(m_pACList));
1139-
if (m_pACList)
1140-
m_pACList->AddRef(); // hold not to be freed
11411135

11421136
UpdateDropDownState(); // create/hide the drop-down window if necessary
11431137

dll/win32/browseui/desktopipc.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
348348
BOOL Ret;
349349

350350
// Tell the thread ref we are using it.
351-
if (parameters && parameters->offsetF8)
352-
parameters->offsetF8->AddRef();
351+
if (parameters && parameters->pExplorerInstance)
352+
parameters->pExplorerInstance->AddRef();
353353

354354
/* Handle /e parameter */
355355
UINT wFlags = 0;
@@ -410,17 +410,11 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
410410
}
411411
}
412412

413-
int nrc = browser->Release();
414-
if (nrc > 0)
415-
{
416-
DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc);
417-
}
418-
419-
browser.Detach();
413+
ReleaseCComPtrExpectZero(browser);
420414

421415
// Tell the thread ref we are not using it anymore.
422-
if (parameters && parameters->offsetF8)
423-
parameters->offsetF8->Release();
416+
if (parameters && parameters->pExplorerInstance)
417+
parameters->pExplorerInstance->Release();
424418

425419
return hResult;
426420
}
@@ -519,8 +513,8 @@ extern "C" void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
519513
param->offset78->Release();
520514
if (param->offsetC != NULL)
521515
param->offsetC->Release();
522-
if (param->offsetF8 != NULL)
523-
param->offsetF8->Release();
516+
if (param->pExplorerInstance != NULL)
517+
param->pExplorerInstance->Release();
524518
LocalFree(param);
525519
}
526520

@@ -563,7 +557,7 @@ extern "C" HRESULT WINAPI SHOpenFolderWindow(PIE_THREAD_PARAM_BLOCK parameters)
563557

564558
PIE_THREAD_PARAM_BLOCK paramsCopy = SHCloneIETHREADPARAM(parameters);
565559

566-
SHGetInstanceExplorer(&(paramsCopy->offsetF8));
560+
SHGetInstanceExplorer(&(paramsCopy->pExplorerInstance));
567561
threadHandle = CreateThread(NULL, 0x10000, BrowserThreadProc, paramsCopy, 0, &threadID);
568562
if (threadHandle != NULL)
569563
{

dll/win32/browseui/internettoolbar.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,6 @@ CInternetToolbar::CInternetToolbar()
614614
fMenuCallback = new CComObject<CMenuCallback>();
615615
fToolbarWindow = NULL;
616616
fAdviseCookie = 0;
617-
618-
fMenuCallback->AddRef();
619617
}
620618

621619
CInternetToolbar::~CInternetToolbar()

dll/win32/browseui/shellbrowser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ HRESULT CShellBrowser::GetBaseBar(bool vertical, REFIID riid, void **theBaseBar)
11211121

11221122
// we have to store our basebar into cache now
11231123
*cache = newBaseBar;
1124-
newBaseBar->AddRef();
1124+
(*cache)->AddRef();
11251125

11261126
// tell the new base bar about the shell browser
11271127
hResult = IUnknown_SetSite(newBaseBar, static_cast<IDropTarget *>(this));

dll/win32/shell32/CFolderItems.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ HRESULT STDMETHODCALLTYPE CFolderItem::get_Parent(IDispatch **ppid)
3838
if (ppid)
3939
{
4040
*ppid = m_Folder;
41-
m_Folder->AddRef();
41+
(*ppid)->AddRef();
4242
}
4343
return E_NOTIMPL;
4444
}

dll/win32/shell32/shelldesktop/CDesktopBrowser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ HRESULT STDMETHODCALLTYPE CDesktopBrowser::QueryActiveShellView(IShellView **pps
321321
if (ppshv == NULL)
322322
return E_POINTER;
323323
*ppshv = m_ShellView;
324-
if (m_ShellView != NULL)
325-
m_ShellView->AddRef();
324+
if (*ppshv != NULL)
325+
(*ppshv)->AddRef();
326326

327327
return S_OK;
328328
}

dll/win32/shell32/shellmenu/CMenuBand.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ HRESULT STDMETHODCALLTYPE CMenuBand::GetMenuInfo(
9999

100100
if (ppsmc)
101101
{
102-
if (m_psmc)
103-
m_psmc->AddRef();
104102
*ppsmc = m_psmc;
103+
if (*ppsmc)
104+
(*ppsmc)->AddRef();
105105
}
106106

107107
if (puId)
@@ -655,8 +655,8 @@ HRESULT STDMETHODCALLTYPE CMenuBand::GetClient(IUnknown **ppunkClient)
655655

656656
if (m_subMenuChild)
657657
{
658-
m_subMenuChild->AddRef();
659658
*ppunkClient = m_subMenuChild;
659+
(*ppunkClient)->AddRef();
660660
}
661661

662662
return S_OK;

sdk/include/reactos/browseui_undoc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct IEThreadParamBlock
6060
UCHAR gap108[24];
6161
DWORD dword120;
6262
DWORD dword124;
63-
IUnknown* offsetF8; // 0x128 instance explorer
63+
IUnknown* pExplorerInstance; // 0x128 instance explorer
6464
UCHAR byteflags_130;
6565
} IE_THREAD_PARAM_BLOCK, * PIE_THREAD_PARAM_BLOCK;
6666
#else
@@ -90,7 +90,7 @@ typedef struct IEThreadParamBlock
9090
char offsetA4[0xD8-0xA4]; // unknown contents -- 0xA4..0xD8
9191
LONG offsetD8;
9292
char offsetDC[0xF8-0xDC]; // unknown contents -- 0xDC..0xF8
93-
IUnknown * offsetF8; // instance explorer
93+
IUnknown * pExplorerInstance; // instance explorer
9494
LONG offsetFC; // unknown contents
9595
} IE_THREAD_PARAM_BLOCK, *PIE_THREAD_PARAM_BLOCK;
9696
#endif

sdk/include/reactos/shellutils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,19 @@ void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
226226
{
227227
if (cptr.p != NULL)
228228
{
229-
int nrc = cptr->Release();
229+
T *raw = cptr.Detach();
230+
int nrc = raw->Release();
230231
if (nrc > 0)
231232
{
232233
DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
233234
if (forceRelease)
234235
{
235236
while (nrc > 0)
236237
{
237-
nrc = cptr->Release();
238+
nrc = raw->Release();
238239
}
239240
}
240241
}
241-
cptr.Detach();
242242
}
243243
}
244244

0 commit comments

Comments
 (0)