<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<div>It seems that I find some memory leak bugs in omni4.1.6 code. These memory leak bugs were detected using the purify tool on the Solaris10 OS.</div>
<div><b>1) /omniORB-4.1.6/src/lib/omniORB/orbcore/tcp/tcpTransportImpl.cc: line 426:</b></div>
<div><div>  while ( 1 ) {</div><div>    // There is no way to know for sure the buffer is big enough to get</div><div>    // the info for all the interfaces. We work around this by calling</div><div>    // the ioctl 2 times and increases the buffer size in the 2nd call.</div>

<div>    // If both calls return the info with the same size, we know we have</div><div>    // got all the interfaces.</div><div>    char* buf = (char*) malloc(len); <font color="#FF6666">[<b>TLazareva]: this is 426 line.</b></font></div>

<div>    ifc.ifc_len = len;</div><div>    ifc.ifc_buf = buf;</div><div>    if ( ioctl(sock, OMNI_SIOCGIFCONF, &amp;ifc) &lt; 0 ) {</div><div>      if ( errno != EINVAL || lastlen != 0 ) {</div><div><span style="white-space:pre-wrap">        </span>if ( omniORB::trace(1) ) {</div>

<div><span style="white-space:pre-wrap">        </span>  omniORB::logger log;</div><div><span style="white-space:pre-wrap">        </span>  log &lt;&lt; &quot;Warning: ioctl SIOCGICONF failed.\n&quot;</div>
<div><span style="white-space:pre-wrap">        </span>      &lt;&lt; &quot;Unable to obtain the list of all interface addresses.\n&quot;;</div><div><span style="white-space:pre-wrap">        </span>} <font color="#FF6666"><b><span style="font-weight:normal">[<b>TLazareva]:</b></span> I think that &quot;buf&quot; variable should be cleaned before &quot;return&quot;: &quot;free buf;&quot; </b></font></div>

<div><span style="white-space:pre-wrap">        </span>return;</div><div>      }</div><div>    }</div><div>    else {</div><div>      if ( ifc.ifc_len == lastlen )</div><div><span style="white-space:pre-wrap">        </span>break; // Success, len has not changed.</div>

<div>      lastlen = ifc.ifc_len;</div><div>    }</div><div>    len += 10 * sizeof(struct ifreq);</div><div>    free(buf);</div><div>  }</div></div><div><b>2) /omniORB-4.1.6/src/lib/omnithread/posix.cc: line 376</b></div>

<div><div>    omni_thread* t = new omni_thread; <span style="color:rgb(255,102,102)"><b><span style="font-weight:normal">[<b>TLazareva]: This is 376 line. &quot;t&quot; object was not deleted at the end of function. Is it correct? Purify detect the memory leak for this object.</b></span></b></span></div>

<div><br></div><div>    t-&gt;_state = STATE_RUNNING;</div><div><br></div><div>    t-&gt;posix_thread = pthread_self ();</div><div><br></div><div>    DB(cerr &lt;&lt; &quot;initial thread &quot; &lt;&lt; t-&gt;id() &lt;&lt; endl);</div>

<div><br></div><div>    THROW_ERRORS(pthread_setspecific(self_key, (void*)t));</div><div><br></div><div>#ifdef PthreadSupportThreadPriority</div><div><br></div><div>#if (PthreadDraftVersion == 4)</div><div><br></div><div>

    THROW_ERRORS(pthread_setprio(t-&gt;posix_thread,</div><div><span style="white-space:pre-wrap">                                </span> posix_priority(PRIORITY_NORMAL)));</div><div><br></div><div>#elif (PthreadDraftVersion == 6)</div>
<div><br></div><div>    pthread_attr_t attr;</div><div>    pthread_attr_init(&amp;attr);</div><div><br></div><div>    THROW_ERRORS(pthread_attr_setprio(&amp;attr, posix_priority(PRIORITY_NORMAL)));</div><div><br></div><div>

    THROW_ERRORS(pthread_setschedattr(t-&gt;posix_thread, attr));</div><div><br></div><div>#else</div><div><br></div><div>    struct sched_param sparam;</div><div><br></div><div>    sparam.sched_priority = posix_priority(PRIORITY_NORMAL);</div>

<div><br></div><div>    THROW_ERRORS(pthread_setschedparam(t-&gt;posix_thread, SCHED_OTHER, &amp;sparam));</div><div><b><font color="#FF6666">[TLazareva]: I think that &quot;t&quot; object should be cleaned before the end of function: &quot;delete t;&quot;</font></b></div>

<div>#endif   /* PthreadDraftVersion */</div><div><br></div><div>#endif   /* PthreadSupportThreadPriority */</div><div>}</div></div><div><div><br></div><div><b>3) /omniORB-4.1.6/src/lib/omniORB/orbcore/portableserver.cc: line 320</b></div>

<div><div><div style="display:inline!important">void*</div></div><div>PortableServer::ServantBase::_do_this(const char* repoId)</div><div>{</div><div>  OMNIORB_ASSERT(repoId);</div><div><br></div><div>  if (!omni::internalLock) {</div>

<div>    // Not initalised yet</div><div>    OMNIORB_THROW(OBJ_ADAPTER,OBJ_ADAPTER_POANotInitialised,</div><div><span style="white-space:pre-wrap">                </span>  CORBA::COMPLETED_NO);</div><div>  }</div><div>
<br></div><div>  omniCurrent* current = omniCurrent::get(); <b><font color="#FF6666">[TLazareva]: This is 320 line. This object is created in /omniORB-4.1.6/include/omniORB4/internal/omniCurrent.h file at the 92 line using &quot;new&quot; operator and this object is not cleaned in the code.</font></b></div>

<div>  if (current) {</div><div>    omniCallDescriptor* call_desc = current-&gt;callDescriptor();</div><div>    if (call_desc &amp;&amp;</div><div><span style="white-space:pre-wrap">        </span>call_desc-&gt;localId()-&gt;servant() == (omniServant*)this) {</div>

<div><br></div><div>      // In context of an invocation on this servant</div><div>      omniObjRef* ref = omniOrbPOACurrent::real_get_reference(call_desc);</div><div>      OMNIORB_ASSERT(ref);<b><font color="#FF6666">[TLazareva]: I think that &quot;current&quot; object should be cleaned before the &quot;return&quot;: &quot;delete current;&quot;</font></b></div>

<div>      return ref-&gt;_ptrToObjRef(repoId);</div><div>    }</div><div>  }</div><div><br></div><div>  {</div><div>    omni_tracedmutex_lock sync(*omni::internalLock);</div><div><br></div><div>    if (_activations().size() == 1) {</div>

<div>      // We only have a single activation -- return a reference to it.</div><div>      omniObjTableEntry* entry = _activations()[0];</div><div>      omniOrbPOA* poa = omniOrbPOA::_downcast(entry-&gt;adapter());</div>

<div>      omniIORHints hints(poa ? poa-&gt;policy_list() : 0);</div><div>      omniObjRef* ref = omni::createLocalObjRef(_mostDerivedRepoId(), repoId,</div><div><span style="white-space:pre-wrap">                                                </span>entry, hints);</div>

<div>      OMNIORB_ASSERT(ref);</div><div>      return ref-&gt;_ptrToObjRef(repoId);</div><div>    }</div><div>  }</div><div><b><br></b></div><div>  PortableServer::POA_var poa = this-&gt;_default_POA();</div><div><br></div>

<div>  if( CORBA::is_nil(poa) )</div><div>    OMNIORB_THROW(OBJ_ADAPTER,OBJ_ADAPTER_POANotInitialised,</div><div><span style="white-space:pre-wrap">                </span>  CORBA::COMPLETED_NO);</div><div><br></div><div>
  return ((omniOrbPOA*)(PortableServer::POA_ptr) poa)-&gt;</div><div>    servant__this(this, repoId);</div><div>}</div></div><div><br></div><div><b>4) /omniORB-4.1.6/src/lib/omnithread/threaddata.cc: line 51</b></div><div>

<div>omni_thread::value_t*</div><div>omni_thread::set_value(key_t k, value_t* v)</div><div>{</div><div>  if (k == 0) return 0;</div><div>  if (k &gt; _value_alloc) {</div><div>    next_id_mutex-&gt;lock();</div><div>    key_t alloc = allocated_keys;</div>

<div>    next_id_mutex-&gt;unlock();</div><div><br></div><div>    if (k &gt; alloc) return 0;</div><div><br></div><div>    value_t** nv = new value_t*[alloc]; <b><font color="#FF6666">[TLazareva]: This is 51 line. &quot;nv&quot; object is not cleaned in the code.</font></b></div>

<div>    key_t i = 0;</div><div>    if (_values) {</div><div>      for (; i &lt; _value_alloc; i++)</div><div><span style="white-space:pre-wrap">        </span>nv[i] = _values[i];</div><div>      delete [] _values;</div>
<div>    }</div><div>    for (; i &lt; alloc; i++)</div><div>      nv[i] = 0;</div><div><br></div><div>    _values = nv;<b><font color="#FF6666">[TLazareva]: As I understand &quot;nv&quot; object is not needed after this line, so it should be deleted: &quot;delete [] nv;&quot;</font></b></div>

<div>    _value_alloc = alloc;</div><div>  }</div><div>  if (_values[k-1]) delete _values[k-1];</div><div>  _values[k-1] = v;</div><div>  return v;</div><div>}</div></div><div><br></div><div>5) /omniORB-4.1.6/build/src/lib/omniORB/omniORB4/Naming.hh: line 404</div>

<div><div>    static inline _ptr_type _unmarshalObjRef(cdrStream&amp; s) {</div><div>      omniObjRef* o = omniObjRef::_unMarshal(_PD_repoId,s); <b><font color="#FF6666">[TLazareva]: This is 404 line.The object &quot;o&quot; is created using &quot;new&quot; operator in /omniORB-4.1.6/build/src/lib/omniORB/omniORB4/NamingSK.cc file at the 2746 line (full stack you can find below). I think that &quot;o&quot; object should be deleted before the &quot;return&quot; like this:</font></b></div>

<div><b><font color="#FF6666">if (o) {</font></b></div><div><font color="#FF6666"><b>  _ptr_type ptrObj = (_ptr_type) o-&gt;_ptrToObjRef(_PD_repoId);</b></font></div><div>
<font color="#FF6666"><b>  delete o;</b></font></div><div><font color="#FF6666"><b>  return ptrObj;</b></font></div><div><b><font color="#FF6666">}</font></b></div>
<div><b><font color="#FF6666">else ...</font></b></div><div>      if (o)</div><div>        return (_ptr_type) o-&gt;_ptrToObjRef(_PD_repoId);</div><div>      else</div><div>        return _nil();</div>
<div>    }</div></div><div><b>Full stack:</b></div><div><div>PLK: 1152 bytes potentially leaked in 18 blocks</div><div>  * This memory was allocated from:</div><div><span style="white-space:pre-wrap">        </span>malloc         [rtlib.o]</div>

<div><span style="white-space:pre-wrap">        </span>operator new(unsigned) [libCrun.a]</div><div><span style="white-space:pre-wrap">        </span>void*operator new(unsigned) [rtlib.o]</div><div><b><font color="#FF6666"><span style="white-space:pre-wrap">        </span>omniObjRef*CosNaming::_pof_NamingContextExt::newObjRef(omniIOR*,omniIdentity*) [NamingSK.cc:2746]</font></b></div>

<div><b><font color="#FF6666"><span style="white-space:pre-wrap">        </span>omniObjRef*omni::createObjRef(const char*,omniIOR*,bool,omniIdentity*) [omniInternal.cc:1069]</font></b></div>
<div><b><font color="#FF6666"><span style="white-space:pre-wrap">        </span>omniObjRef*omniObjRef::_unMarshal(const char*,cdrStream&amp;) [omniObjRef.cc:990]</font></b></div><div><b><font color="#FF6666"><span style="white-space:pre-wrap">        </span>CosNaming::_objref_NamingContext*CosNaming::NamingContext::_unmarshalObjRef(cdrStream&amp;) [Naming.hh:404]</font></b></div>

<div><span style="white-space:pre-wrap">        </span>void _0RL_cd_69CECA6A39F685B5_e0000000::unmarshalReturnedValues(cdrStream&amp;) [NamingSK.cc:1334]</div><div><span style="white-space:pre-wrap">        </span>void omniRemoteIdentity::dispatch(omniCallDescriptor&amp;) [remoteIdentity.cc:188]</div>

<div><span style="white-space:pre-wrap">        </span>void omniObjRef::_invoke(omniCallDescriptor&amp;,bool) [omniObjRef.cc:783]</div><div><span style="white-space:pre-wrap">        </span>CosNaming::_objref_NamingContext*CosNaming::_objref_NamingContext::bind_new_context(const CosNaming::Name&amp;) [NamingSK.cc:1426]</div>

<div><span style="white-space:pre-wrap">        </span>_CORBA_ObjRef_Var&lt;CosNaming::_objref_NamingContext,CosNaming::NamingContext_Helper&gt;corba::Orb::_bindNewContext(_CORBA_ObjRef_Var&lt;CosNaming::_objref_NamingContext,CosNaming::NamingContext_Helper&gt;,const CosNaming::Name&amp;) [Orb.cc:154]</div>

<div>  * Block of 64 bytes (18 times); last block at 0x27e8948</div></div><div><br></div><div><br></div><div>Could you please check the code above on the memory leak issue?<span class="HOEnZb"><font color="#888888"><br clear="all">
</font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><p><font face="&#39;Book Antiqua&#39;, serif"></font></p>
<p><font face="&#39;Book Antiqua&#39;, serif"><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;"><span></span>Cheers,</span></font></p><font face="&#39;Book Antiqua&#39;, serif">

<p><b><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;;color:red">T</span></b><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;">atiana <b><span style="color:red">L</span></b>azareva</span><b><span style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;"></span></b></p>

</font><p></p><p><font face="&#39;Book Antiqua&#39;, serif" color="#333333">e-mail (regular):</font><font face="&#39;Book Antiqua&#39;, serif" color="#333333"> </font><font face="&#39;Book Antiqua&#39;, serif" color="#FF6666"><u><a href="mailto:Tatiana.Alexandrovna.Lazareva@gmail.com" target="_blank">Tatiana.Alexandrovna.Lazareva@gmail.com</a></u></font></p>


</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><p><font face="&#39;Book Antiqua&#39;, serif"></font></p><p><font face="&#39;Book Antiqua&#39;, serif"><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;"><span></span>Cheers,</span></font></p>
<font face="&#39;Book Antiqua&#39;, serif">

<p><b><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;;color:red">T</span></b><span lang="EN-US" style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;">atiana <b><span style="color:red">L</span></b>azareva</span><b><span style="font-family:&quot;Book Antiqua&quot;,&quot;serif&quot;"></span></b></p>
</font><p></p><p><font face="&#39;Book Antiqua&#39;, serif" color="#333333">e-mail (regular):</font><font face="&#39;Book Antiqua&#39;, serif" color="#333333"> </font><font face="&#39;Book Antiqua&#39;, serif" color="#FF6666"><u><a href="mailto:Tatiana.Alexandrovna.Lazareva@gmail.com" target="_blank">Tatiana.Alexandrovna.Lazareva@gmail.com</a></u></font></p>
<p><font face="&#39;Book Antiqua&#39;, serif"><font color="#333333">e-mail (office): </font><u><font color="#FF6666"><a href="mailto:yumanova@mera.ru" target="_blank">yumanova@mera.ru</a></font></u></font></p><br>
</div>