Browse Source

variable_watch: Prevent making extra entries in the watch map

When removing a watch on a variable, using the operator [] on the
internal map will create an empty watch if the variable doesn't have any
existing watches. Rather than creating this empty structure in the map,
return if there isn't a watch on the variable already.
Ben Boeckel 12 years ago
parent
commit
00ce12a334
1 changed files with 4 additions and 0 deletions
  1. 4 0
      Source/cmVariableWatch.cxx

+ 4 - 0
Source/cmVariableWatch.cxx

@@ -80,6 +80,10 @@ void cmVariableWatch::RemoveWatch(const std::string& variable,
                                   WatchMethod method,
                                   WatchMethod method,
                                   void* client_data /*=0*/)
                                   void* client_data /*=0*/)
 {
 {
+  if ( !this->WatchMap.count(variable) )
+    {
+    return;
+    }
   cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
   cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable];
   cmVariableWatch::VectorOfPairs::iterator it;
   cmVariableWatch::VectorOfPairs::iterator it;
   for ( it = vp->begin(); it != vp->end(); ++it )
   for ( it = vp->begin(); it != vp->end(); ++it )