[vtk-developers] DebugLeaks C++ expert issue?

Ken Martin ken.martin at kitware.com
Mon Jan 7 11:39:17 EST 2019


On VS2017 Debug with DEBUG_LEAKS I'm seeing an odd issue. DebugLeaks is
complaining about vtkCommands being leaked because the two string literals
in the below code have different addresses (the string address is used in a
map type structure). Looking at DebugLeaks the only way this code would
work is if they have the same address. But I checked in the debugger and
they have different addresses.


//----------------------------------------------------------------
vtkCommand::vtkCommand():AbortFlag(0),PassiveObserver(0)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass("vtkCommand or subclass");
#endif
}

//----------------------------------------------------------------
void vtkCommand::UnRegister()
{
int refcount = this->GetReferenceCount()-1;
this->SetReferenceCount(refcount);
if (refcount <= 0)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::DestructClass("vtkCommand or subclass");
#endif
delete this;
}
}

I can fix it by doing the following but wanted a c++ expert to weigh in,
was the original code OK? Is this a compiler compliance issue? Is the
proposed fix the right approach?

const char *cname = "vtkCommand or subclass";

//----------------------------------------------------------------
vtkCommand::vtkCommand():AbortFlag(0),PassiveObserver(0)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass(cname);
#endif
}

//----------------------------------------------------------------
void vtkCommand::UnRegister()
{
int refcount = this->GetReferenceCount()-1;
this->SetReferenceCount(refcount);
if (refcount <= 0)
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::DestructClass(cname);
#endif
delete this;
}
}


Thanks!
Ken


-- 
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
101 East Weaver Street
Carrboro, North Carolina
27510 USA

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee.  Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtk-developers/attachments/20190107/807f137a/attachment.html>


More information about the vtk-developers mailing list