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

Yves Frederix yves.frederix+cmake at gmail.com
Tue Mar 22 15:25:13 EDT 2016


Hi Brad,

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,
Yves

On Tue, Mar 22, 2016 at 4:48 PM, Brad King <brad.king at kitware.com> wrote:
> On 03/22/2016 10:52 AM, Yves Frederix wrote:
>> What happens is that 'def' is assigned at the beginning of the
>> function, but during the call to  vv->VariableAccessed(...), there is
>> an internal memory re-allocation
>
> Thanks for tracking this down!  Let's just add a
>
>   std::string local_def = def;
>
> inside the variable watch block so we have a locally-owned
> string to pass instead.  I'm not concerned about the cost of
> the local allocation because this variable watches are for
> debugging anyway.
>
> Please look at doing that every where VariableAccessed
> is called.
>
> Thanks,
> -Brad
>


More information about the cmake-developers mailing list