[Live-devel] memory leak? some questions
pan_xiaolei
pan_xiaolei at sina.com
Sat Sep 1 04:26:58 PDT 2007
I was puzzled when I'v read the following code:
OnDemandServerMediaSubsession.cpp:447 StreamState::startPlaying()
if (dests- >isTCP) {
// Change RTP and RTCP to use the TCP socket instead of UDP:
if (fRTPSink != NULL) {
fRTPSink- >addStreamSocket(dests- >tcpSocketNum, dests- >rtpChannelId);
}
if (fRTCPInstance != NULL) {
fRTCPInstance- >addStreamSocket(dests- >tcpSocketNum, dests- >rtcpChannelId);
fRTCPInstance- >setSpecificRRHandler(dests- >tcpSocketNum, dests- >rtcpChannelId,
rtcpRRHandler, rtcpRRHandlerClientData);
}
} else {
// Tell the RTP and RTCP 'groupsocks' about this destination
// (in case they don't already have it):
if (fRTPgs != NULL) fRTPgs- >addDestination(dests- >addr, dests- >rtpPort);
if (fRTCPgs != NULL) fRTCPgs- >addDestination(dests- >addr, dests- >rtcpPort);
if (fRTCPInstance != NULL) {
fRTCPInstance- >setSpecificRRHandler(dests- >addr.s_addr, dests- >rtcpPort,
rtcpRRHandler, rtcpRRHandlerClientData);
}
}
1) why we have make sure the fRTPSink, fRTCPInstance, fRTPgs, fRTCPgs is not NULL. After the SETUP, all of them must have been allocated.
2) why not use fRTPSink and fRTCPInstance to instead of the fRTPgs and fRTCPgs when call addDestination? In my opionion, as the fRTPgs and
fRTCPgs has been encapsulated into the fRTPSink and fRTCPInstance, they should be managed by the fRTPSink and fRTCPInstance only. I think
the code "fRTPSink- >addDestination() fRTCPInstance - >addDestination()" may be more easily to understand, don't you?
OnDemandServerMediaSubsession.cpp:200 StreamState::getStreamParameters()
for (portNumBits serverPortNum = fInitialPortNum; ; serverPortNum += 2) {
struct in_addr dummyAddr; dummyAddr.s_addr = 0;
serverRTPPort = serverPortNum;
rtpGroupsock = new Groupsock(envir(), dummyAddr, serverRTPPort, 255);
if (rtpGroupsock- >socketNum() < 0) {
delete rtpGroupsock;
continue; // try again
}
serverRTCPPort = serverPortNum+1;
rtcpGroupsock = new Groupsock(envir(), dummyAddr, serverRTCPPort, 255);
if (rtcpGroupsock- >socketNum() < 0) {
delete rtcpGroupsock;
continue; // try again
}
break; // success
}
1) As more and more client has connected to the server, the available port of the system may be very few. At that time, the searching for a pair of available port will become a block operation, which will affect to complete other requests effectively.
2) Consider the following scene:
the port, 6640, 6642 and 6643, are free ports. The rtpSocket will be happy when she finds the 6640 is a free port, but the rtcpSocket will be unhappy, because 6641 has been ocupied for some reason. Then the loop continue, while the rtcpSocket is freed and rtpSocke is still allocated, MEMORY LEAK!
David Pan
2007-09-01
More information about the live-devel
mailing list