[prev in list] [next in list] [prev in thread] [next in thread]
List: ms-dcom
Subject: Re: Help Needed
From: Vincent Parla <vparla () CISCO ! COM>
Date: 2004-05-04 16:11:32
Message-ID: 000e01c431f2$77d7e220$5a4f2ca1 () vparlalap
[Download RAW message or body]
Clearly your code is not thread safe. Can release be called by more than
one thread?
You should be using ::InterlockedIncrement/Decrement of your longs values.
-----Original Message-----
From: Distributed COM-Based Code [mailto:DCOM@DISCUSS.MICROSOFT.COM] On
Behalf Of Seshu Madabushi
Sent: Tuesday, May 04, 2004 11:33 AM
To: DCOM@DISCUSS.MICROSOFT.COM
Subject: Re: Help Needed
I am using BoundsChecker, but it is not saying any memory leaks, no wrong
pointers to free etc.
I am pasting part of the code here, loading and unloading the libraries.
Please let me know if I am doing anything wrong.
Thanks
Seshu
Release Function
STDMETHODIMP_(ULONG)LIB::Release( void )
{
m_ulRef--; //value is 1 lets say right now.
//What if your are pre-empted right here in first thread ?
if( 0 == m_ulRef )
{
delete this;
g_ulObjects--;
if( ::ServerCanUnloadNow() )
::UnloadServer();
return( 0 );
}
return( m_ulRef );
}
BOOL ServerCanUnloadNow( void )
{
if( 0 == g_ulObjects && 0 == g_ulLocks )
return( TRUE );
else
return( FALSE );
}
void UnloadServer( void )
{
return;
}
Loading the Library
STDMETHODIMP LIBFactory::CreateInstance( IUnknown* pUnknownOuter, REFIID
iid, LPVOID* ppv ) {
// declare local variables
HRESULT hr;
LIB* PLIB = NULL;
// disallow aggregation
*ppv = NULL;
if( NULL != pUnknownOuter )
return( CLASS_E_NOAGGREGATION );
// attempt to allocate storage for instance
PLIB = new PLIB();
if( NULL == PLIB )
return( E_OUTOFMEMORY );
// query the interface
hr = PLIB->QueryInterface( iid, ppv );
if( FAILED( hr ))
{
delete PLIB;
PLIB = NULL;
return( hr );
}
// increment object counter
g_ulObjects++;
return( NOERROR );
}
Is there anything wrong in the initialize and release calls?
Thanks
Seshu
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html . To unsubscribe,
mailto:DCOM-signoff-request@DISCUSS.MICROSOFT.COM
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request@DISCUSS.MICROSOFT.COM
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic