1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_WIN_SCOPED_CO_MEM_H_
6 #define BASE_WIN_SCOPED_CO_MEM_H_
10 #include "base/basictypes.h"
11 #include "base/logging.h"
16 // Simple scoped memory releaser class for COM allocated memory.
18 // base::win::ScopedCoMem<ITEMIDLIST> file_item;
19 // SHGetSomeInfo(&file_item, ...);
21 // return; <-- memory released
25 ScopedCoMem() : mem_ptr_(NULL
) {}
30 T
** operator&() { // NOLINT
31 DCHECK(mem_ptr_
== NULL
); // To catch memory leaks.
40 DCHECK(mem_ptr_
!= NULL
);
44 const T
* operator->() const {
45 DCHECK(mem_ptr_
!= NULL
);
51 CoTaskMemFree(mem_ptr_
);
58 DISALLOW_COPY_AND_ASSIGN(ScopedCoMem
);
64 #endif // BASE_WIN_SCOPED_CO_MEM_H_