[Live-devel] Memory leaks ?

kamil kamildobk at poczta.onet.pl
Thu Sep 8 18:14:47 PDT 2005


Hi,
I tested openRTSP.exe and located a few memory-leaks.

1. I run openRTSP.exe -e 5 rtsp://192.168.7.199/mpeg4/1/media.amp

subsession.sessionId is not deleted, it is called only in 
teardownMediaSubsession, which is not called anywhere. Unfortunately it is 
not called in teardownMediaSession(). I changed subsession destructor by 
adding delete[] sessionId.

MediaSubsession::~MediaSubsession()
{
 delete sessionId;
}

2. I run TCP tunneled RTP by: openRTSP.exe -t -e 5 
rtsp://192.168.7.199/mpeg4/1/media.amp

'socketTable' is not removed. It is deleted in ~RCTPInstance(), but next it 
is immediately created again in ~MuliFramedRTPSource, and not deleted again 
because it is empty.
You create 'socketTable' on request in socketHashTable(), but delete it only 
in removeSocketDescriptor() which is error-prone as 'socketTable' is created 
initially empty, so removeSocketDescriptor() will not be called in every 
situation. I changed it to:

void _Tables::reclaimIfPossible() {
    if ( socketTable && ((HashTable*)socketTable)->IsEmpty() )
    {
        delete (HashTable*)socketTable; socketTable = NULL;
    }
    if ( mediaTable == NULL && socketTable == NULL )
    {
        fEnv.liveMediaPriv = NULL; // so why not 
fEnv->reclaimTablesIfPossible() and fEnv->getOutTables() ?
       delete this;
    }
}

and now it deletes socketTable in each situation.

2. I run HTTP tunneled RTP by: openRTSP.exe -t -e 5 
rtsp://192.168.7.199/mpeg4/1/media.amp

In function RTSPClient::setupHTTPTunneling() variable cmd is not deleted 
after first request. I added a single line:

if ( !sendRequest( cmd, "HTTP GET", False)) break;
delete[] cmd; cmd = NULL;

And there is no memory leaks now. Unfortuanately, I was not able to run 
openRTSP.exe in multicast mode, so far ( please help ! ), so I was not able 
to test multicast connection.

PS.
Although those are minor issues it would be easier to track any mistakes if 
all objects allocated and deleted only their own members. For example:

MediaSubSession::SetSessionId( char *sessionId )
{
 delete[] mSessionId; mSessionId = ::strDup(sessionId);
}

MediaSubsession::~MediaSubsession()
{
 delete mSessionId;
}

or
UsageEnvironment::reclaimTablesIfPossible()
UsageEnvironment::getOurTables()
( it would create UsageEnvironment<-_Tables dependency but it is not such 
wrong )

Also I think that a simple string-wrapper class to manipulate strings, would 
clean the code much.

And what do you think ?

Regards,
Kamil Dobkowski


_________________________________________________________________
List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )


More information about the live-devel mailing list