<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div style="color: rgb(0, 0, 0);">
<div id="divRplyFwdMsg" dir="ltr"></div>
<meta content="text/html; charset=iso-8859-1">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>I'm looking at what looks to me to be a memory leak when using the any type and looking for some help resolving.</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span><br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span>   TAO VERSION: 2.2a_p14<br>
</span>
<div><br>
</div>
<div>    HOST MACHINE and OPERATING SYSTEM: Should be an issue on all platforms.  I found on RHEL 7.5 using valgrind/gdb.<br>
</div>
<div><br>
</div>
<div>    TARGET MACHINE and OPERATING SYSTEM, if different from HOST: Nope<br>
</div>
<div>    COMPILER NAME AND VERSION (AND PATCHLEVEL):  gcc version 4.4.7 20120313 (Red Hat 4.4.7-17)<br>
</div>
<div><br>
</div>
<div>    CONTENTS OF $ACE_ROOT/ace/config.h [if you use a link to a platform-<br>
</div>
<div>    specific file, simply state which one]:<br>
</div>
<div><br>
</div>
<div>    CONTENTS OF $ACE_ROOT/include/makeinclude/platform_macros.GNU [if you<br>
</div>
<div>    use a link to a platform-specific file, simply state which one<br>
</div>
<div>    (unless this isn't used in this case, e.g., with Microsoft Visual<br>
</div>
<div>    C++)]:<br>
</div>
<div><br>
</div>
<div>    CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features<br>
</div>
<div>    (used by MPC when you generate your own makefiles):<br>
</div>
<div><br>
</div>
<div>    LEVEL OF URGENCY (LOW, MEDIUM, or HIGH): MEDIUM<br>
</div>
<div><br>
</div>
<div>    AREA/CLASS/EXAMPLE AFFECTED:<br>
</div>
<div>AnyTypeCode<br>
</div>
<div><br>
</div>
<div>    DOES THE PROBLEM AFFECT:<br>
</div>
<div>        COMPILATION? Nope<br>
</div>
<div>        LINKING? Nope<br>
</div>
<div>            On Unix systems, did you run make realclean first?<br>
</div>
<div>        EXECUTION? Yes, memory leak found during execution<br>
</div>
<div>        OTHER (please specify)?<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>    SYNOPSIS: </div>
<div>Memory/reference leaked in Any_Impl::marshal.  ValueBase pointer is set via to_value() function and never freed or decremented in the function or any function called by Any_Impl::marshal.<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>    DESCRIPTION:<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>TAO::Any_Impl::marshal calls the to_value function with a ValueBase pointer.  This function can allocate memory using a factory or increment a reference count.  Neither the marshal or the to_value function appear to have any current means to clean-up the
 reference.</div>
<div><br>
</div>
</div>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>CORBA::<span>Boolean</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>TAO::Any_Impl::marshal</span> (TAO_OutputCDR &cdr)</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>{</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>CORBA::ValueBase * vb = <span>0</span>;</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>if</span> (<b><i><u><span>this</span>-><span>to_value</span> (vb) </u></i></b>&& vb)</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>{</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> Since we ARE a value type, we need to</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> send the ACTUAL derived typecode for</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> the type we are marshaling NOT the</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> typecode of the base pointer that may</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> have been inserted into the any.</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>if</span> ((cdr << <span>TAO_ORB_Core_instance</span> ()</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>-><span>valuetype_adapter</span>()</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>-><span>derived_type</span> (vb)) == <span>0</span>)</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>{</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>return</span> <span>false</span>;</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>}</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>}</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> Otherwise send the typecode of the inserted type.</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>else</span> <span>if</span> ((cdr << <span>this</span>-><span>type_</span>) ==
<span>0</span>)</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>{</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>return</span> <span>false</span>;</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>}</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> Once the typecode has been marshaled send the actual</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span><span>//</span> value (this is polymorphic for valuetypes)</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><span>return</span> <span>this</span>-><span>marshal_value</span> (cdr);</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>}</div>
</div>
</blockquote>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div><br>
</div>
<div>The to_value function as generated here: be/be_visitor_valuetype/any_op_cs.cpp:48 show the reference count is incremented</div>
<div><br>
</div>
</div>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td>*os << be_nl_2</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>namespace TAO<span>"</span></span> << be_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>{<span>"</span></span> << be_idt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>template<><span>"</span></span> << be_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>::CORBA::Boolean<span>"</span></span> << be_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>Any_Impl_T<<span>"</span></span> << node-><span>name</span> () <<
<span><span>"</span>>::to_value (<span>"</span></span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< be_idt << be_idt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>::CORBA::ValueBase *&_tao_elem) const<span>"</span></span> << be_uidt</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< be_uidt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>{<span>"</span></span> << be_idt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span></span><b><i><u>::CORBA::add_ref (this->value_);" </u>
</i></b><< be_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>_tao_elem = this->value_;<span>"</span></span> << be_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>return true;<span>"</span></span> << be_uidt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<table>
<tbody>
<tr>
<td><< <span><span>"</span>}<span>"</span></span> << be_uidt_nl</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div><< <span><span>"</span>}<span>"</span></span> << be_nl_2;</div>
</div>
</blockquote>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div><br>
</div>
<div>and I believe via the TAO::Unknown_IDL_Type::to_value() we can also get a new object via a factory method.  In my case I found the issue via the generated to_value function in my idl generated C.cpp file implementation which incremented the reference count.</div>
<div><br>
</div>
<div>    REPEAT BY:<br>
</div>
<div><br>
</div>
<div>I can work on providing a small sample test case if needed.</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>    SAMPLE FIX/WORKAROUND:<br>
</div>
<span></span><br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I would propose a fix of modifying the ::marshal function to use a ValueBase_var type to track the reference count:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td>--CORBA::ValueBase * vb =<span> </span><span style="margin:0px">0</span>;<br>
++CORBA::ValueBase_var vb;</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px">--if</span><span> </span>(<span style="margin:0px">this</span>-><span style="margin:0px">to_value</span><span> </span>(vb) && vb)<br>
++if (this->to_value(vb.out())) && (0 != vb.ptr()))</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">{</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px"><span style="margin:0px">//</span><span> </span>Since we ARE a value type, we need to</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px"><span style="margin:0px">//</span><span> </span>send the ACTUAL derived typecode for</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px"><span style="margin:0px">//</span><span> </span>the type we are marshaling NOT the</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px"><span style="margin:0px">//</span><span> </span>typecode of the base pointer that may</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px"><span style="margin:0px">//</span><span> </span>have been inserted into the any.</span></td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td><span style="margin:0px">if</span><span> </span>((cdr <<<span> </span><span style="margin:0px">TAO_ORB_Core_instance</span><span> </span>()</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td>-><span style="margin:0px">valuetype_adapter</span>()</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
</div>
<div style="margin:0px; font-size:12pt; background-color:rgb(255,255,255)">
<div style="margin:0px">
<table>
<tbody>
<tr>
<td>--   -><span style="margin:0px">derived_type</span><span> </span>(vb)) ==<span> </span><span style="margin:0px">0</span>)</td>
</tr>
<tr>
</tr>
</tbody>
</table>
++ ->derived_type(vb.in())) == 0)</div>
</div>
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
However, this introduces a new dependency on TAO_ValueType for TAO_AnyTypeCode and this would create a circular dependency between the two libraries.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I'm looking for some advice on how best to resolve; </div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Do I look to separate library creation steps on windows to create the import library/export file as a separate step from the link and keep the AnyTypeCode/ValueType structure (I'm not quite sure how to do that yet with MPC)?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Or do I look to combine the two into a single dll and eliminate the circular dependency?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Or is there some other solution that resolves the memory leak while avoiding circular dependency that I haven't been able to see or a work-around that others have used to avoid leaking memory here?</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Thanks,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Dan Kempenich.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
</div>
</div>
</div>
</body>
</html>