[EXPLORER][BROWSEUI][SHELL32][NETSHELL] Fix wrong usage of CComPtr

This commit is contained in:
Mark Jansen 2022-09-18 20:59:00 +02:00
parent a414c88dae
commit cd2d284142
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
13 changed files with 23 additions and 41 deletions

View file

@ -242,8 +242,5 @@ public:
HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu) HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu)
{ {
CStartMenuBtnCtxMenu * mnu = new CComObject<CStartMenuBtnCtxMenu>(); return ShellObjectCreatorInit<CStartMenuBtnCtxMenu>(m_TrayWnd, m_Owner, IID_PPV_ARG(IContextMenu, ppCtxMenu));
mnu->Initialize(m_TrayWnd, m_Owner);
*ppCtxMenu = mnu;
return S_OK;
} }

View file

@ -301,8 +301,8 @@ public:
if (ppcm != NULL) if (ppcm != NULL)
{ {
m_ContextMenu->AddRef();
*ppcm = m_ContextMenu; *ppcm = m_ContextMenu;
(*ppcm)->AddRef();
} }
/* Add the menu items */ /* Add the menu items */

View file

@ -2943,7 +2943,6 @@ ChangePos:
{ {
CComPtr<IContextMenu> ctxMenu; CComPtr<IContextMenu> ctxMenu;
CStartMenuBtnCtxMenu_CreateInstance(this, m_hWnd, &ctxMenu); CStartMenuBtnCtxMenu_CreateInstance(this, m_hWnd, &ctxMenu);
ctxMenu->AddRef();
TrackCtxMenu(ctxMenu, ppt, hWndExclude, m_Position == ABE_BOTTOM, this); TrackCtxMenu(ctxMenu, ppt, hWndExclude, m_Position == ABE_BOTTOM, this);
} }
} }

View file

@ -953,7 +953,7 @@ CLanStatus::InitializeNetTaskbarNotifications()
pItem->uID = Index; pItem->uID = Index;
pItem->pNext = NULL; pItem->pNext = NULL;
pItem->pNet = pNetCon; pItem->pNet = pNetCon;
pNetCon->AddRef(); pItem->pNet->AddRef();
hwndDlg = CreateDialogParamW(netshell_hInstance, MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext); hwndDlg = CreateDialogParamW(netshell_hInstance, MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext);
if (!hwndDlg) if (!hwndDlg)
{ {

View file

@ -1126,18 +1126,12 @@ CAutoComplete::Init(HWND hwndEdit, IUnknown *punkACL,
::GetWindowRect(m_hwndEdit, &m_rcEdit); ::GetWindowRect(m_hwndEdit, &m_rcEdit);
// get an IEnumString // get an IEnumString
ATLASSERT(!m_pEnum);
punkACL->QueryInterface(IID_IEnumString, (VOID **)&m_pEnum); punkACL->QueryInterface(IID_IEnumString, (VOID **)&m_pEnum);
TRACE("m_pEnum: %p\n", static_cast<void *>(m_pEnum)); TRACE("m_pEnum: %p\n", static_cast<void *>(m_pEnum));
if (m_pEnum)
m_pEnum->AddRef(); // hold not to be freed
// get an IACList // get an IACList
ATLASSERT(!m_pACList);
punkACL->QueryInterface(IID_IACList, (VOID **)&m_pACList); punkACL->QueryInterface(IID_IACList, (VOID **)&m_pACList);
TRACE("m_pACList: %p\n", static_cast<void *>(m_pACList)); TRACE("m_pACList: %p\n", static_cast<void *>(m_pACList));
if (m_pACList)
m_pACList->AddRef(); // hold not to be freed
UpdateDropDownState(); // create/hide the drop-down window if necessary UpdateDropDownState(); // create/hide the drop-down window if necessary

View file

@ -348,8 +348,8 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
BOOL Ret; BOOL Ret;
// Tell the thread ref we are using it. // Tell the thread ref we are using it.
if (parameters && parameters->offsetF8) if (parameters && parameters->pExplorerInstance)
parameters->offsetF8->AddRef(); parameters->pExplorerInstance->AddRef();
/* Handle /e parameter */ /* Handle /e parameter */
UINT wFlags = 0; UINT wFlags = 0;
@ -410,17 +410,11 @@ static HRESULT ExplorerMessageLoop(IEThreadParamBlock * parameters)
} }
} }
int nrc = browser->Release(); ReleaseCComPtrExpectZero(browser);
if (nrc > 0)
{
DbgPrint("WARNING: There are %d references to the CShellBrowser active or leaked.\n", nrc);
}
browser.Detach();
// Tell the thread ref we are not using it anymore. // Tell the thread ref we are not using it anymore.
if (parameters && parameters->offsetF8) if (parameters && parameters->pExplorerInstance)
parameters->offsetF8->Release(); parameters->pExplorerInstance->Release();
return hResult; return hResult;
} }
@ -519,8 +513,8 @@ extern "C" void WINAPI SHDestroyIETHREADPARAM(IEThreadParamBlock *param)
param->offset78->Release(); param->offset78->Release();
if (param->offsetC != NULL) if (param->offsetC != NULL)
param->offsetC->Release(); param->offsetC->Release();
if (param->offsetF8 != NULL) if (param->pExplorerInstance != NULL)
param->offsetF8->Release(); param->pExplorerInstance->Release();
LocalFree(param); LocalFree(param);
} }
@ -563,7 +557,7 @@ extern "C" HRESULT WINAPI SHOpenFolderWindow(PIE_THREAD_PARAM_BLOCK parameters)
PIE_THREAD_PARAM_BLOCK paramsCopy = SHCloneIETHREADPARAM(parameters); PIE_THREAD_PARAM_BLOCK paramsCopy = SHCloneIETHREADPARAM(parameters);
SHGetInstanceExplorer(&(paramsCopy->offsetF8)); SHGetInstanceExplorer(&(paramsCopy->pExplorerInstance));
threadHandle = CreateThread(NULL, 0x10000, BrowserThreadProc, paramsCopy, 0, &threadID); threadHandle = CreateThread(NULL, 0x10000, BrowserThreadProc, paramsCopy, 0, &threadID);
if (threadHandle != NULL) if (threadHandle != NULL)
{ {

View file

@ -614,8 +614,6 @@ CInternetToolbar::CInternetToolbar()
fMenuCallback = new CComObject<CMenuCallback>(); fMenuCallback = new CComObject<CMenuCallback>();
fToolbarWindow = NULL; fToolbarWindow = NULL;
fAdviseCookie = 0; fAdviseCookie = 0;
fMenuCallback->AddRef();
} }
CInternetToolbar::~CInternetToolbar() CInternetToolbar::~CInternetToolbar()

View file

@ -1121,7 +1121,7 @@ HRESULT CShellBrowser::GetBaseBar(bool vertical, REFIID riid, void **theBaseBar)
// we have to store our basebar into cache now // we have to store our basebar into cache now
*cache = newBaseBar; *cache = newBaseBar;
newBaseBar->AddRef(); (*cache)->AddRef();
// tell the new base bar about the shell browser // tell the new base bar about the shell browser
hResult = IUnknown_SetSite(newBaseBar, static_cast<IDropTarget *>(this)); hResult = IUnknown_SetSite(newBaseBar, static_cast<IDropTarget *>(this));

View file

@ -38,7 +38,7 @@ HRESULT STDMETHODCALLTYPE CFolderItem::get_Parent(IDispatch **ppid)
if (ppid) if (ppid)
{ {
*ppid = m_Folder; *ppid = m_Folder;
m_Folder->AddRef(); (*ppid)->AddRef();
} }
return E_NOTIMPL; return E_NOTIMPL;
} }

View file

@ -321,8 +321,8 @@ HRESULT STDMETHODCALLTYPE CDesktopBrowser::QueryActiveShellView(IShellView **pps
if (ppshv == NULL) if (ppshv == NULL)
return E_POINTER; return E_POINTER;
*ppshv = m_ShellView; *ppshv = m_ShellView;
if (m_ShellView != NULL) if (*ppshv != NULL)
m_ShellView->AddRef(); (*ppshv)->AddRef();
return S_OK; return S_OK;
} }

View file

@ -99,9 +99,9 @@ HRESULT STDMETHODCALLTYPE CMenuBand::GetMenuInfo(
if (ppsmc) if (ppsmc)
{ {
if (m_psmc)
m_psmc->AddRef();
*ppsmc = m_psmc; *ppsmc = m_psmc;
if (*ppsmc)
(*ppsmc)->AddRef();
} }
if (puId) if (puId)
@ -655,8 +655,8 @@ HRESULT STDMETHODCALLTYPE CMenuBand::GetClient(IUnknown **ppunkClient)
if (m_subMenuChild) if (m_subMenuChild)
{ {
m_subMenuChild->AddRef();
*ppunkClient = m_subMenuChild; *ppunkClient = m_subMenuChild;
(*ppunkClient)->AddRef();
} }
return S_OK; return S_OK;

View file

@ -60,7 +60,7 @@ typedef struct IEThreadParamBlock
UCHAR gap108[24]; UCHAR gap108[24];
DWORD dword120; DWORD dword120;
DWORD dword124; DWORD dword124;
IUnknown* offsetF8; // 0x128 instance explorer IUnknown* pExplorerInstance; // 0x128 instance explorer
UCHAR byteflags_130; UCHAR byteflags_130;
} IE_THREAD_PARAM_BLOCK, * PIE_THREAD_PARAM_BLOCK; } IE_THREAD_PARAM_BLOCK, * PIE_THREAD_PARAM_BLOCK;
#else #else
@ -90,7 +90,7 @@ typedef struct IEThreadParamBlock
char offsetA4[0xD8-0xA4]; // unknown contents -- 0xA4..0xD8 char offsetA4[0xD8-0xA4]; // unknown contents -- 0xA4..0xD8
LONG offsetD8; LONG offsetD8;
char offsetDC[0xF8-0xDC]; // unknown contents -- 0xDC..0xF8 char offsetDC[0xF8-0xDC]; // unknown contents -- 0xDC..0xF8
IUnknown * offsetF8; // instance explorer IUnknown * pExplorerInstance; // instance explorer
LONG offsetFC; // unknown contents LONG offsetFC; // unknown contents
} IE_THREAD_PARAM_BLOCK, *PIE_THREAD_PARAM_BLOCK; } IE_THREAD_PARAM_BLOCK, *PIE_THREAD_PARAM_BLOCK;
#endif #endif

View file

@ -226,7 +226,8 @@ void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
{ {
if (cptr.p != NULL) if (cptr.p != NULL)
{ {
int nrc = cptr->Release(); T *raw = cptr.Detach();
int nrc = raw->Release();
if (nrc > 0) if (nrc > 0)
{ {
DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc); DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
@ -234,11 +235,10 @@ void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
{ {
while (nrc > 0) while (nrc > 0)
{ {
nrc = cptr->Release(); nrc = raw->Release();
} }
} }
} }
cptr.Detach();
} }
} }