Author: dquintana Date: Mon Mar 16 20:47:05 2015 New Revision: 66745 URL: http://svn.reactos.org/svn/reactos?rev=66745&view=rev Log: [NTOBJSHEX] * Fix leak of the PIDL and PIDL Manager from the shell folder destructors. * Switch PIDL Manager to a lazy enumeration so it won't lookup the folder contents unless/until they are needed.
Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp Modified: trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp?rev=66745&r1=66744&r2=66745&view=diff ============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/ntobjns.cpp [iso-8859-1] Mon Mar 16 20:47:05 2015 @@ -177,6 +177,15 @@ HRESULT Initialize(PWSTR ntPath) { m_ntPath = ntPath; + m_hDpa = NULL; + + return S_OK; + } + + HRESULT Enumerate() + { + if (m_hDpa) + return S_OK; m_hDpa = DPA_Create(10); @@ -196,7 +205,12 @@ if (!m_hDpa) { - return E_FAIL; + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; } NtPidlEntry * info = (NtPidlEntry *) pcidl; @@ -234,9 +248,16 @@ HRESULT FindByName(LPCWSTR strParsingName, NtPidlEntry ** pinfo) { + HRESULT hr; + if (!m_hDpa) { - return E_FAIL; + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; } TRACE("Searching for '%S' in a list of %d items\n", strParsingName, m_hDpaCount); @@ -263,6 +284,18 @@ HRESULT GetPidl(UINT index, NtPidlEntry ** pEntry) { + HRESULT hr; + + if (!m_hDpa) + { + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; + } + *pEntry = NULL; NtPidlEntry * entry = (NtPidlEntry *) DPA_GetPtr(m_hDpa, index); @@ -277,10 +310,21 @@ HRESULT GetCount(UINT * count) { + HRESULT hr; + + if (!m_hDpa) + { + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; + } + *count = m_hDpaCount; return S_OK; } - static LPITEMIDLIST CreatePidlFromItem(NtPidlEntry * entry) { @@ -292,7 +336,7 @@ return idl; } - HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, NtPidlEntry * second) + static HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, NtPidlEntry * second) { if ((lParam & 0xFFFF0000) == SHCIDS_ALLFIELDS) { @@ -387,7 +431,7 @@ return E_INVALIDARG; } - HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, LPCITEMIDLIST pcidl) + static HRESULT CompareIDs(LPARAM lParam, NtPidlEntry * first, LPCITEMIDLIST pcidl) { LPCITEMIDLIST p = pcidl; NtPidlEntry * second = (NtPidlEntry*) &(p->mkid); @@ -397,7 +441,7 @@ return CompareIDs(lParam, first, second); } - HRESULT CompareIDs(LPARAM lParam, LPCITEMIDLIST pcidl1, LPCITEMIDLIST pcidl2) + static HRESULT CompareIDs(LPARAM lParam, LPCITEMIDLIST pcidl1, LPCITEMIDLIST pcidl2) { LPCITEMIDLIST p = pcidl1; NtPidlEntry * first = (NtPidlEntry*) &(p->mkid); @@ -407,7 +451,7 @@ return CompareIDs(lParam, first, pcidl2); } - ULONG ConvertAttributes(NtPidlEntry * entry, PULONG inMask) + static ULONG ConvertAttributes(NtPidlEntry * entry, PULONG inMask) { ULONG mask = inMask ? *inMask : 0xFFFFFFFF; ULONG flags = SFGAO_HASPROPSHEET | SFGAO_CANLINK; @@ -564,7 +608,10 @@ CNtObjectFolder::~CNtObjectFolder() { - TRACE("Destroying CNtObjectFolder %p\n", this); + if (m_shellPidl) + ILFree(m_shellPidl); + if (m_PidlManager) + delete m_PidlManager; } // IShellFolder Modified: trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp?rev=66745&r1=66744&r2=66745&view=diff ============================================================================== --- trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/shellext/ntobjshex/regfolder.cpp [iso-8859-1] Mon Mar 16 20:47:05 2015 @@ -164,6 +164,15 @@ { m_ntPath = ntPath; m_hRoot = hRoot; + m_hDpa = NULL; + + return S_OK; + } + + HRESULT Enumerate() + { + if (m_hDpa) + return S_OK; m_hDpa = DPA_Create(10); @@ -182,7 +191,6 @@ if (FAILED_UNEXPECTEDLY(hr)) return hr; } - return S_OK; } @@ -192,7 +200,12 @@ if (!m_hDpa) { - return E_FAIL; + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; } RegPidlEntry * info = (RegPidlEntry *) pcidl; @@ -230,10 +243,18 @@ HRESULT FindByName(LPCWSTR strParsingName, RegPidlEntry ** pinfo) { + HRESULT hr; + if (!m_hDpa) { - return E_FAIL; - } + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; + } + TRACE("Searching for '%S' in a list of %d items\n", strParsingName, m_hDpaCount); @@ -259,6 +280,18 @@ HRESULT GetPidl(UINT index, RegPidlEntry ** pEntry) { + HRESULT hr; + + if (!m_hDpa) + { + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; + } + *pEntry = NULL; RegPidlEntry * entry = (RegPidlEntry *) DPA_GetPtr(m_hDpa, index); @@ -273,6 +306,18 @@ HRESULT GetCount(UINT * count) { + HRESULT hr; + + if (!m_hDpa) + { + hr = Enumerate(); + if (FAILED_UNEXPECTEDLY(hr)) + return hr; + + if (!m_hDpa) + return E_FAIL; + } + *count = m_hDpaCount; return S_OK; } @@ -288,7 +333,7 @@ return idl; } - HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, RegPidlEntry * second) + static HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, RegPidlEntry * second) { if ((lParam & 0xFFFF0000) == SHCIDS_ALLFIELDS) { @@ -373,7 +418,7 @@ return E_INVALIDARG; } - HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, LPCITEMIDLIST pcidl) + static HRESULT CompareIDs(LPARAM lParam, RegPidlEntry * first, LPCITEMIDLIST pcidl) { LPCITEMIDLIST p = pcidl; RegPidlEntry * second = (RegPidlEntry*) &(p->mkid); @@ -383,7 +428,7 @@ return CompareIDs(lParam, first, second); } - HRESULT CompareIDs(LPARAM lParam, LPCITEMIDLIST pcidl1, LPCITEMIDLIST pcidl2) + static HRESULT CompareIDs(LPARAM lParam, LPCITEMIDLIST pcidl1, LPCITEMIDLIST pcidl2) { LPCITEMIDLIST p = pcidl1; RegPidlEntry * first = (RegPidlEntry*) &(p->mkid); @@ -393,7 +438,7 @@ return CompareIDs(lParam, first, pcidl2); } - ULONG ConvertAttributes(RegPidlEntry * entry, PULONG inMask) + static ULONG ConvertAttributes(RegPidlEntry * entry, PULONG inMask) { ULONG mask = inMask ? *inMask : 0xFFFFFFFF; ULONG flags = 0; @@ -416,7 +461,7 @@ (entry->entryType == REG_ENTRY_ROOT); } - HRESULT FormatValueData(DWORD contentType, PVOID td, DWORD contentsLength, PCWSTR * strContents) + static HRESULT FormatValueData(DWORD contentType, PVOID td, DWORD contentsLength, PCWSTR * strContents) { switch (contentType) { @@ -647,7 +692,10 @@ CRegistryFolder::~CRegistryFolder() { - TRACE("Destroying CRegistryFolder %p\n", this); + if (m_shellPidl) + ILFree(m_shellPidl); + if (m_PidlManager) + delete m_PidlManager; } // IShellFolder