cmVariableWatch: Fix potential memory leak

Teach cmVariableWatch::AddWatch to own the Pair it allocates until
it needs to pass ownership to WatchMap.
This commit is contained in:
Brad King 2016-05-25 09:58:36 -04:00
parent 6052e4b3bf
commit 75e3e0d3dc
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}