This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Memory leak in pthread_setcanceltype()?


Hello,

I'm using Pthreads win32 (snapshot 2000-09-08) with Visual C++ (6.0) and
Windows2000 and I am getting lots of memory leaks flagged by Purify and
BoundsChecker.  I'm using the precompiled DLL obtained from
<ftp://sources.redhat.com/pub/pthreads-win32/dll-latest>.

These leaks occur in (at least) calls to phread_mutex_lock(),
pthread_cond_wait() and pthread_cond_timedwait() and at typically about 28
bytes per leak.

Purify reports these memory leaks as:

MLK: Memory leak of 28 bytes from 1 block allocated in pthread_setcanceltype
        Distribution of leaked blocks
                28 bytes from 1 block of 28 bytes (0x02105db0) 
        Allocation location
            calloc         [msvcrt.DLL]
            pthread_setcanceltype [pthreadVSE.dll]
            pthread_setcanceltype [pthreadVSE.dll]
            pthread_setcanceltype [pthreadVSE.dll]
            SDSUtility::Mutex::lock(void) [SDSUtility_Mutex.cpp:61]
                {
                #ifdef _MT
                
             =>     pthread_mutex_lock( &m_objectMutex );
                
                #endif
                }
and:

MLK: Memory leak of 20 bytes from 1 block allocated in pthread_setcanceltype
        Distribution of leaked blocks
                20 bytes from 1 block of 20 bytes (0x02106200) 
        Allocation location
            calloc         [msvcrt.DLL]
            pthread_setcanceltype [pthreadVSE.dll]
            pthread_setcanceltype [pthreadVSE.dll]
            pthread_setcanceltype [pthreadVSE.dll]
            pthread_setcanceltype [pthreadVSE.dll]
            SDSDataStore::Query::waitForTrigger(void)
[SDSDataStore_Query.cpp:136]
                    if( !m_triggered && !m_terminated )
                    {
             =>         pthread_cond_wait( &m_triggered_cond, &m_mutex );
                    }

BoundsChecker reports the first leak as:

Bounds checker reports this as:

Memory leak: 28 bytes allocated by calloc in PTHREADVSE.DLL!00002AC1,HANDLE:
0x00303A10
PTHREADVSE.DLL!00002AC1()	(unknown)	(unknown)
PTHREADVSE.DLL!00002AC1()	(unknown)	(unknown)
PTHREADVSE.DLL!00002AC1()	(unknown)	(unknown)
SDSUtility::Mutex::lock()
C:\Scorpion\source\SDSUtility\SDSUtility_Mutex.cpp	61


Does anybody know if this is a known problem?  Can anybody point me to
something I could be doing wrong to cause this problem.  I have tried using
both the VSE and VCE versions.  I also hacked up a simple program which
locks and unlocks a pthread mutex and purify does not find any leaks in it
so it is likely to be something within my more complicated program but I'm
not sure what I can do to release memory allocated by a call to
pthread_mutex_lock() - have I missed something?

Below is my implementation of my Mutex class whose lock() methods creates
the first leak listed above, just incase anybody can see anything obviously
stupid in this.
 
Any help in pointing me in the right direction would be very much
appreciated.

Thanks,

Ally Hume
Concept Systems Limited


Mutex.h

#include <pthread.h>

class Mutex 
{
public:

    /// Constructor
    Mutex();

    /// Destructor
    ~Mutex();

    /**
    *** Locks the mutex.  Blocks until the lock is obtained
    **/
    void lock();

    /**
    *** Unlocks the mutex
    **/
    void unlock();

private:

    // Synchronization object

#ifdef _MT

    pthread_mutex_t    m_objectMutex;                       ///< global
object mutex

#endif

};


Mutex.cpp

/// Constructor
Mutex::Mutex()
#ifdef _MT
    : m_objectMutex( PTHREAD_MUTEX_INITIALIZER )
#endif
{
}
    
/// Destructor
Mutex::~Mutex()
{
}

/**
*** Locks the mutex.  Blocks until the lock is obtained
**/
void 
Mutex::lock()
{
#ifdef _MT

    pthread_mutex_lock( &m_objectMutex );

#endif
}


/**
*** Unlocks the mutex
**/
void 
Mutex::unlock()
{
#ifdef _MT

    pthread_mutex_unlock( &m_objectMutex );

#endif
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]