<div dir="ltr"><div><br></div><div>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.<br></div><div><br></div><div><br></div><div>

<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(106,153,85)">//----------------------------------------------------------------</span></div><div><span style="color:rgb(220,220,170)">vtkCommand::vtkCommand</span><span style="color:rgb(212,212,212)">():</span><span style="color:rgb(220,220,170)">AbortFlag</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">),</span><span style="color:rgb(220,220,170)">PassiveObserver</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">{</span></div><div><span style="color:rgb(197,134,192)">#ifdef</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(220,220,170)">VTK_DEBUG_LEAKS</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(220,220,170)">vtkDebugLeaks::ConstructClass</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(206,145,120)">"vtkCommand or subclass"</span><span style="color:rgb(212,212,212)">);</span></div><div><span style="color:rgb(197,134,192)">#endif</span></div><div><span style="color:rgb(212,212,212)">}</span></div><br><div><span style="color:rgb(106,153,85)">//----------------------------------------------------------------</span></div><div><span style="color:rgb(86,156,214)">void</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">vtkCommand::UnRegister</span><span style="color:rgb(212,212,212)">()</span></div><div><span style="color:rgb(212,212,212)">{</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> refcount </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">-></span><span style="color:rgb(220,220,170)">GetReferenceCount</span><span style="color:rgb(212,212,212)">()</span><span style="color:rgb(212,212,212)">-</span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">-></span><span style="color:rgb(220,220,170)">SetReferenceCount</span><span style="color:rgb(212,212,212)">(refcount);</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(212,212,212)"> (refcount </span><span style="color:rgb(212,212,212)"><=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">  {</span></div><div><span style="color:rgb(197,134,192)">#ifdef</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(220,220,170)">VTK_DEBUG_LEAKS</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(220,220,170)">vtkDebugLeaks::DestructClass</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(206,145,120)">"vtkCommand or subclass"</span><span style="color:rgb(212,212,212)">);</span></div><div><span style="color:rgb(197,134,192)">#endif</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(197,134,192)">delete</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)">  }</span></div><div><span style="color:rgb(212,212,212)">}</span></div></div>

</div><div><br></div><div>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?<br></div><div><br></div><div>

<div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">const</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">char</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(212,212,212)">*</span><span style="color:rgb(212,212,212)">cname </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(206,145,120)">"vtkCommand or subclass"</span><span style="color:rgb(212,212,212)">;</span></div><br><div><span style="color:rgb(106,153,85)">//----------------------------------------------------------------</span></div><div><span style="color:rgb(220,220,170)">vtkCommand::vtkCommand</span><span style="color:rgb(212,212,212)">():</span><span style="color:rgb(220,220,170)">AbortFlag</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">),</span><span style="color:rgb(220,220,170)">PassiveObserver</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">{</span></div><div><span style="color:rgb(197,134,192)">#ifdef</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(220,220,170)">VTK_DEBUG_LEAKS</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(220,220,170)">vtkDebugLeaks::ConstructClass</span><span style="color:rgb(212,212,212)">(cname);</span></div><div><span style="color:rgb(197,134,192)">#endif</span></div><div><span style="color:rgb(212,212,212)">}</span></div><br><div><span style="color:rgb(106,153,85)">//----------------------------------------------------------------</span></div><div><span style="color:rgb(86,156,214)">void</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">vtkCommand::UnRegister</span><span style="color:rgb(212,212,212)">()</span></div><div><span style="color:rgb(212,212,212)">{</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> refcount </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">-></span><span style="color:rgb(220,220,170)">GetReferenceCount</span><span style="color:rgb(212,212,212)">()</span><span style="color:rgb(212,212,212)">-</span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">-></span><span style="color:rgb(220,220,170)">SetReferenceCount</span><span style="color:rgb(212,212,212)">(refcount);</span></div><div><span style="color:rgb(212,212,212)">  </span><span style="color:rgb(197,134,192)">if</span><span style="color:rgb(212,212,212)"> (refcount </span><span style="color:rgb(212,212,212)"><=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">  {</span></div><div><span style="color:rgb(197,134,192)">#ifdef</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(220,220,170)">VTK_DEBUG_LEAKS</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(220,220,170)">vtkDebugLeaks::DestructClass</span><span style="color:rgb(212,212,212)">(cname);</span></div><div><span style="color:rgb(197,134,192)">#endif</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(197,134,192)">delete</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">this</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)">  }</span></div><div><span style="color:rgb(212,212,212)">}</span></div><br></div>

</div><div><br></div><div>Thanks!</div><div>Ken</div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Ken Martin PhD<div>Distinguished Engineer<br><span style="font-size:12.8px">Kitware Inc.</span><br></div><div>101 East Weaver Street<br>Carrboro, North Carolina<br>
27510 USA<br><br><div><span style="font-size:10pt;font-family:Tahoma,sans-serif">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.</span></div></div></div></div></div></div></div></div>