I used visual leak detector 1.0 which seems to be more effective at
tracking leaks in sipxtapi than 1.9f.

And I get "Visual Leak Detector detected 1061 memory leaks." !!

The problem is there are lots of dynamic singletons all over the code.
Some of them can be converted to static, i.e:

class Singleton
{
public:

Singleton& instance() { return &instance}

private:

static Singleton instance;

};

Singleton Singleton::instance;

But in order for this to work, the constructor and destructor can't use
static members of other classes, or call functions that do it (as those
static members could be uninitialized). There are compiler depended ways
to deal with the order of static initialization (#pragma init in visual
studio, and __attribute__ ((init_priority (somenumber))) for gcc), but
its not a nice way to solve this problem.

Could you start using this pattern for future singletons? It is slightly
more dangerous, but if you are careful with constructor/destructor it
should be fine. It's really hard to do any leak finding if there are
1000 memory leaks.

I'm sending a patch for SipSubscribeServer which works for me, but it
should be tested on Linux using the unit tests. In the destructor there
is warning 3 members shouldn't be deleted, as they are "owned" by
somebody else. But since they are private, created in SipSubscribeServer
 they should be deleted there as well. In fact, they are not deleted at
all, and if sipxtapi is reinitialized these 3 cause a memory leak. I
expect it could cause some problems in Linux unittests, but those
problems shouldn't be fixed by not deleting objects.

Another memory leak I found is in sipxtapi call data structure. So after
each call, some memory is leaked.

There is a missing "delete pData->contactAddress;" in "void
destroyCallData(SIPX_CALL_DATA* pData)". Please note this is not needed:

if(pData->contactAddress != NULL)
{
        delete pData->contactAddress;
        pData->contactAddress = NULL;
}

pData is deleted later anyway, and delete automatically tests if
contactAddress  is not NULL.
So its enough to just put

delete pData->contactAddress;

Jaroslav Libak

Index: src/net/SipSubscribeServer.cpp
===================================================================
--- src/net/SipSubscribeServer.cpp      (revision 9091)
+++ src/net/SipSubscribeServer.cpp      (working copy)
@@ -128,6 +128,9 @@
     *   they are owned by whoever constructed this server.
     */
 
+   delete mpDefaultEventHandler;
+   delete mpDefaultSubscriptionMgr;
+   delete mpDefaultContentMgr;
     // Iterate through and delete all the event data
     // TODO:
 }
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to