Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

C++ code exhibits a Mutant Handle leak that causes the handles and memory to grow rapidly

user12279926Nov 26 2013

Hello everyone,

Could anybody please help me solve this issue......

The following code exhibits a Mutant Handle leak that causes the handles and memory to grow rapidly. The issue only occurs when a connection is created from a thread. In the code, if the function (myThread) is called instead of using a beginthread, the code no longer has the handle leak. However when the beginthread is used; then memory and handles grow.

Thanks in advance!!!

Environment:

Visual C++ 2010

64-Bit Libraries

Oracle Client 12C

Windows 7 Enterprise SP1

Code:

#include "stdafx.h"

#include <Windows.h>

#include <string>

#include "OCCI.h"

#include <process.h>

void myThread(void * pVoid)

{

       oracle::occi::Connection *m_pConn;

oracle::occi::ConnectionPool *m_pConnPool = (oracle::occi::ConnectionPool*)pVoid;

      

       try

       {

if ( m_pConnPool )

{

m_pConn = m_pConnPool->createConnection( "mySchema", "password"  );

m_pConnPool->terminateConnection( m_pConn );

}

       }

       catch( oracle::occi::SQLException e )

       {

       }

       catch(...)

       {

       }

       _endthread();

}

int _tmain(int argc, _TCHAR* argv[])

{

oracle::occi::Environment *m_pEnv;

oracle::occi::ConnectionPool *m_pConnPool;

       try

       {

m_pEnv = oracle::occi::Environment::createEnvironment( oracle::occi::Environment::THREADED_MUTEXED );

Sleep(300);

m_pConnPool = m_pEnv->createConnectionPool( "mySchema", "password", "myDBName", 1, 70, 1 );

if ( m_pConnPool )

{

m_pConnPool->setTimeOut( 60 );

while(1)

{

_beginthread(myThread,0, m_pConnPool);

// Calling myThread directly does not create the handle leak; the leak only happens when using the thread

//myThread(m_pConnPool);

Sleep(1000);

}

}

       }

       catch( oracle::occi::SQLException e )

       {

       }

       catch(...)

       {

       }

       if(m_pConnPool)

m_pEnv->terminateConnectionPool(m_pConnPool);

       if(m_pEnv)

oracle::occi::Environment::terminateEnvironment(m_pEnv);

       return 0;

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 24 2013
Added on Nov 26 2013
0 comments
1,057 views