<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, &ifc) < 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 << "Warning: ioctl SIOCGICONF failed.\n"</div>
<div><span style="white-space:pre-wrap">        </span> << "Unable to obtain the list of all interface addresses.\n";</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 "buf" variable should be cleaned before "return": "free buf;" </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. "t" 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->_state = STATE_RUNNING;</div><div><br></div><div> t->posix_thread = pthread_self ();</div><div><br></div><div> DB(cerr << "initial thread " << t->id() << 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->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(&attr);</div><div><br></div><div> THROW_ERRORS(pthread_attr_setprio(&attr, posix_priority(PRIORITY_NORMAL)));</div><div><br></div><div>
THROW_ERRORS(pthread_setschedattr(t->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->posix_thread, SCHED_OTHER, &sparam));</div><div><b><font color="#FF6666">[TLazareva]: I think that "t" object should be cleaned before the end of function: "delete t;"</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 "new" operator and this object is not cleaned in the code.</font></b></div>
<div> if (current) {</div><div> omniCallDescriptor* call_desc = current->callDescriptor();</div><div> if (call_desc &&</div><div><span style="white-space:pre-wrap">        </span>call_desc->localId()->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 "current" object should be cleaned before the "return": "delete current;"</font></b></div>
<div> return ref->_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->adapter());</div>
<div> omniIORHints hints(poa ? poa->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->_ptrToObjRef(repoId);</div><div> }</div><div> }</div><div><b><br></b></div><div> PortableServer::POA_var poa = this->_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)-></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 > _value_alloc) {</div><div> next_id_mutex->lock();</div><div> key_t alloc = allocated_keys;</div>
<div> next_id_mutex->unlock();</div><div><br></div><div> if (k > alloc) return 0;</div><div><br></div><div> value_t** nv = new value_t*[alloc]; <b><font color="#FF6666">[TLazareva]: This is 51 line. "nv" object is not cleaned in the code.</font></b></div>
<div> key_t i = 0;</div><div> if (_values) {</div><div> for (; i < _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 < alloc; i++)</div><div> nv[i] = 0;</div><div><br></div><div> _values = nv;<b><font color="#FF6666">[TLazareva]: As I understand "nv" object is not needed after this line, so it should be deleted: "delete [] nv;"</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& s) {</div><div> omniObjRef* o = omniObjRef::_unMarshal(_PD_repoId,s); <b><font color="#FF6666">[TLazareva]: This is 404 line.The object "o" is created using "new" 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 "o" object should be deleted before the "return" 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->_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->_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&) [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&) [Naming.hh:404]</font></b></div>
<div><span style="white-space:pre-wrap">        </span>void _0RL_cd_69CECA6A39F685B5_e0000000::unmarshalReturnedValues(cdrStream&) [NamingSK.cc:1334]</div><div><span style="white-space:pre-wrap">        </span>void omniRemoteIdentity::dispatch(omniCallDescriptor&) [remoteIdentity.cc:188]</div>
<div><span style="white-space:pre-wrap">        </span>void omniObjRef::_invoke(omniCallDescriptor&,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&) [NamingSK.cc:1426]</div>
<div><span style="white-space:pre-wrap">        </span>_CORBA_ObjRef_Var<CosNaming::_objref_NamingContext,CosNaming::NamingContext_Helper>corba::Orb::_bindNewContext(_CORBA_ObjRef_Var<CosNaming::_objref_NamingContext,CosNaming::NamingContext_Helper>,const CosNaming::Name&) [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="'Book Antiqua', serif"></font></p>
<p><font face="'Book Antiqua', serif"><span lang="EN-US" style="font-family:"Book Antiqua","serif""><span></span>Cheers,</span></font></p><font face="'Book Antiqua', serif">
<p><b><span lang="EN-US" style="font-family:"Book Antiqua","serif";color:red">T</span></b><span lang="EN-US" style="font-family:"Book Antiqua","serif"">atiana <b><span style="color:red">L</span></b>azareva</span><b><span style="font-family:"Book Antiqua","serif""></span></b></p>
</font><p></p><p><font face="'Book Antiqua', serif" color="#333333">e-mail (regular):</font><font face="'Book Antiqua', serif" color="#333333"> </font><font face="'Book Antiqua', 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="'Book Antiqua', serif"></font></p><p><font face="'Book Antiqua', serif"><span lang="EN-US" style="font-family:"Book Antiqua","serif""><span></span>Cheers,</span></font></p>
<font face="'Book Antiqua', serif">
<p><b><span lang="EN-US" style="font-family:"Book Antiqua","serif";color:red">T</span></b><span lang="EN-US" style="font-family:"Book Antiqua","serif"">atiana <b><span style="color:red">L</span></b>azareva</span><b><span style="font-family:"Book Antiqua","serif""></span></b></p>
</font><p></p><p><font face="'Book Antiqua', serif" color="#333333">e-mail (regular):</font><font face="'Book Antiqua', serif" color="#333333"> </font><font face="'Book Antiqua', 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="'Book Antiqua', 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>