summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-19 15:56:44 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-19 15:56:44 +0000
commit8103783ca34d7ac9c8ed7a4d15ac6a936f4c2b40 (patch)
tree99c5d8ee4b26cf36ab761173a288eb9c525b4d2c
parent8ca280e9a3c5df4013776bb8d0218b44a092f6ea (diff)
downloadchromium_src-8103783ca34d7ac9c8ed7a4d15ac6a936f4c2b40.zip
chromium_src-8103783ca34d7ac9c8ed7a4d15ac6a936f4c2b40.tar.gz
chromium_src-8103783ca34d7ac9c8ed7a4d15ac6a936f4c2b40.tar.bz2
Make ScopedCoMem class/struct friendly by adding operator->().
Also adding a Reset method and a DCHECK to catch memory leaks. Review URL: http://codereview.chromium.org/8356003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106288 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/scoped_co_mem.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/chrome/common/scoped_co_mem.h b/chrome/common/scoped_co_mem.h
index 33d6cc4..6af28fd 100644
--- a/chrome/common/scoped_co_mem.h
+++ b/chrome/common/scoped_co_mem.h
@@ -9,6 +9,7 @@
#include <objbase.h>
#include "base/basictypes.h"
+#include "base/logging.h"
namespace chrome {
namespace common {
@@ -22,14 +23,13 @@ namespace common {
template<typename T>
class ScopedCoMem {
public:
- explicit ScopedCoMem() : mem_ptr_(NULL) {}
-
+ ScopedCoMem() : mem_ptr_(NULL) {}
~ScopedCoMem() {
- if (mem_ptr_)
- CoTaskMemFree(mem_ptr_);
+ Reset(NULL);
}
T** operator&() { // NOLINT
+ DCHECK(mem_ptr_ == NULL); // To catch memory leaks.
return &mem_ptr_;
}
@@ -37,6 +37,22 @@ class ScopedCoMem {
return mem_ptr_;
}
+ T* operator->() {
+ DCHECK(mem_ptr_ != NULL);
+ return mem_ptr_;
+ }
+
+ const T* operator->() const {
+ DCHECK(mem_ptr_ != NULL);
+ return mem_ptr_;
+ }
+
+ void Reset(T* ptr) {
+ if (mem_ptr_)
+ CoTaskMemFree(mem_ptr_);
+ mem_ptr_ = ptr;
+ }
+
private:
T* mem_ptr_;