[SDK] ReleaseCComPtrExpectZero should print the relevant file:line (#6772)

ReleaseCComPtrExpectZero currently always prints the same line from shellutils.h in the warning which is not very useful. A macro is required for __FILE__ to be correct.
This commit is contained in:
Whindmar Saksit 2024-05-02 17:56:28 +02:00 committed by GitHub
parent 515f998f0d
commit ef80b3dde4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -227,25 +227,23 @@ public:
#endif
template<class T>
void ReleaseCComPtrExpectZero(CComPtr<T>& cptr, BOOL forceRelease = FALSE)
ULONG ReleaseCComPtrExpectZeroHelper(const char *file, UINT line, CComPtr<T>& cptr, BOOL forceRelease = FALSE)
{
ULONG r = 0;
if (cptr.p != NULL)
{
T *raw = cptr.Detach();
int nrc = raw->Release();
int nrc = r = raw->Release();
if (nrc > 0)
Win32DbgPrint(file, line, "WARNING: Unexpected RefCount > 0 (%d)\n", nrc);
while (nrc > 0 && forceRelease)
{
DbgPrint("WARNING: Unexpected RefCount > 0 (%d)!\n", nrc);
if (forceRelease)
{
while (nrc > 0)
{
nrc = raw->Release();
}
}
nrc = raw->Release();
}
}
return r;
}
#define ReleaseCComPtrExpectZero(...) ReleaseCComPtrExpectZeroHelper(__FILE__, __LINE__, __VA_ARGS__)
template<class T, class R>
HRESULT inline ShellDebugObjectCreator(REFIID riid, R ** ppv)