diff options
author | Brad King <brad.king@kitware.com> | 2016-05-25 13:58:36 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-25 13:58:36 (GMT) |
commit | 75e3e0d3dcd7d17a45e2d00148b496013423d210 (patch) | |
tree | 39f927c9114ce4105eac8e777539b8df5b2f0235 /Source/cmVariableWatch.cxx | |
parent | 6052e4b3bfe62a8d29ca679affb101c7aec0d219 (diff) | |
download | CMake-75e3e0d3dcd7d17a45e2d00148b496013423d210.zip CMake-75e3e0d3dcd7d17a45e2d00148b496013423d210.tar.gz CMake-75e3e0d3dcd7d17a45e2d00148b496013423d210.tar.bz2 |
cmVariableWatch: Fix potential memory leak
Teach cmVariableWatch::AddWatch to own the Pair it allocates until
it needs to pass ownership to WatchMap.
Diffstat (limited to 'Source/cmVariableWatch.cxx')
-rw-r--r-- | Source/cmVariableWatch.cxx | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx index ac2f2fa..11eaa93 100644 --- a/Source/cmVariableWatch.cxx +++ b/Source/cmVariableWatch.cxx @@ -13,6 +13,8 @@ #include "cmAlgorithms.h" +#include <cmsys/auto_ptr.hxx> + static const char* const cmVariableWatchAccessStrings[] = { "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS", "MODIFIED_ACCESS", "REMOVED_ACCESS", "NO_ACCESS" @@ -46,7 +48,7 @@ bool cmVariableWatch::AddWatch(const std::string& variable, WatchMethod method, void* client_data /*=0*/, DeleteData delete_data /*=0*/) { - cmVariableWatch::Pair* p = new cmVariableWatch::Pair; + cmsys::auto_ptr<cmVariableWatch::Pair> p(new cmVariableWatch::Pair); p->Method = method; p->ClientData = client_data; p->DeleteDataCall = delete_data; @@ -60,7 +62,7 @@ bool cmVariableWatch::AddWatch(const std::string& variable, WatchMethod method, return false; } } - vp->push_back(p); + vp->push_back(p.release()); return true; } |