diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 08:20:17 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 08:20:17 +0000 |
commit | a026ce05c0ef18e259902da9164fa79116bb6aee (patch) | |
tree | 494d31fc10784a4467063fef249bbc746dbd3da3 /app/win_util.cc | |
parent | 74bb68315422a57f06d953065d2b966f234aa0fb (diff) | |
download | chromium_src-a026ce05c0ef18e259902da9164fa79116bb6aee.zip chromium_src-a026ce05c0ef18e259902da9164fa79116bb6aee.tar.gz chromium_src-a026ce05c0ef18e259902da9164fa79116bb6aee.tar.bz2 |
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
Diffstat (limited to 'app/win_util.cc')
-rw-r--r-- | app/win_util.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/app/win_util.cc b/app/win_util.cc index 2d8c3f3..bbd2a04 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -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); } |