Skip to content
Snippets Groups Projects
Commit a026ce05 authored by hbono@chromium.org's avatar hbono@chromium.org
Browse files

Add clean-up code to SetAppIdForWindow().

This is a follow-up change for r21596.
It seems this change forgot calling pps->Release() and PropVariantClear(&pv). (InitPropVariantFromString() calls SHStrDupW() to create a copy of its input string, so we have to call PropVariantClear() and delete it.)
To avoid an object leak and a memory leak, this change uses ScopedComPtr<IPropertyStore> to call Release() in its destructor and call PropVariantClear() to clean-up PROPVARIANT.
(My JumpList class uses a class which encapsulates PROPVARIANT. We should move the class to win_util?)

BUG=none
TEST=none (Run Chromium on purify running on Windows 7.)
Review URL: http://codereview.chromium.org/160150

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21830 0039d316-1c4b-4281-b951-d872f2087c98
parent 74bb6831
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
#include "base/logging.h"
#include "base/native_library.h"
#include "base/registry.h"
#include "base/scoped_comptr_win.h"
#include "base/scoped_handle.h"
#include "base/string_util.h"
#include "base/win_util.h"
......@@ -868,14 +869,17 @@ void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) {
PROPVARIANT pv;
InitPropVariantFromString(app_id.c_str(), &pv);
IPropertyStore* pps;
ScopedComPtr<IPropertyStore> pps;
SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function);
if (S_OK == SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps)) &&
S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv)) {
pps->Commit();
HRESULT result = SHGetPropertyStoreForWindow(
hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive()));
if (S_OK == result) {
if (S_OK == pps->SetValue(PKEY_AppUserModel_ID, pv))
pps->Commit();
}
// Cleanup.
PropVariantClear(&pv);
base::UnloadNativeLibrary(shell32_library);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment