[cmake-developers] Storage reallocation inside std::vector causing memory problem when using variable_watch

Brad King brad.king at kitware.com
Tue Mar 22 15:37:40 EDT 2016


On 03/22/2016 03:25 PM, Yves Frederix wrote:
> Do I understand it correctly that you suggest to pass a locally-owned
> copy of the string into the call to VariableAccessed? If so, then I am
> not sure how this would solve the problem. The problem is not that def
> is changed by VariableAccessed, the problem is that the original char*
> after calling this function sometimes no longer points to a valid
> location in memory. Or am I missing something here?

Thanks, I missed the problem for the `return def` line.  However, I
think both places are a problem.  I think it is simplest to just
re-lookup the variable value at the end of the variable watch if()
block.

> 3. Define a move constructor in the cmDefinitions class. Probably that
> is not an option as IIRC CMake uses C++98. I did, however, check this
> solution locally, compiling CMake using VS2012 and can verify that it
> fixes the problem.

CMake actually does build as C++11 or C++14 by default with some
compilers, but we must retain the ability to build and work as C++98.
One could conditionally define a move constructor simply to improve
efficiency when we do build as C++11.  The above fix would still be
needed though.

Thanks,
-Brad



More information about the cmake-developers mailing list