Преглед на файлове

COMP: fix possible poroblem with freed memory

Ken Martin преди 20 години
родител
ревизия
de89c6fa69
променени са 1 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 6 2
      Source/cmForEachCommand.cxx

+ 6 - 2
Source/cmForEachCommand.cxx

@@ -34,7 +34,11 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
     if(!expandedArguments.empty() && (expandedArguments[0] == m_Args[0]))
     if(!expandedArguments.empty() && (expandedArguments[0] == m_Args[0]))
       {
       {
       // store the old value
       // store the old value
-      const char *oldDef = mf.GetDefinition(m_Args[0].c_str());
+      std::string oldDef;
+      if (mf.GetDefinition(m_Args[0].c_str()))
+        {
+        oldDef = mf.GetDefinition(m_Args[0].c_str());
+        }
       m_Executing = true;
       m_Executing = true;
       std::vector<std::string>::const_iterator j = m_Args.begin();
       std::vector<std::string>::const_iterator j = m_Args.begin();
       ++j;
       ++j;
@@ -52,7 +56,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf)
           }
           }
         }
         }
       // restore the variable to its prior value
       // restore the variable to its prior value
-      mf.AddDefinition(m_Args[0].c_str(),oldDef);
+      mf.AddDefinition(m_Args[0].c_str(),oldDef.c_str());
       mf.RemoveFunctionBlocker(lff);
       mf.RemoveFunctionBlocker(lff);
       return true;
       return true;
       }
       }