I added the ::close() and the file pointer = 0 to all points where it throws exceptions in TcpSocket.cpp -- this fixed the issue where it would continue trying to write to the socket even though it was already closed by an error thanks to flush statements in the close method of TcpSocket and it's superclasses. This was causing the infinite loop on reconnect when there was still data in the buffer waiting to be transmitted (flushed) when the server closes the socket.

The other issue we fixed is that the aacpEncoder was not being tore down correctly so that when close() is called then it is open()ed again, it would carry on some of the state from the previous open()ing causing a read or write past the end of the buffer and resulting in a segfault core dump. The fix was to copy the variable initialization from the header file into the open() function just after the sanity checking code. This may potentially result in a memory leak as I don't understand the aacplus library's API well enough to know whether or not its resources are being properly freed.

by 
rfc822sucks at hotmail.com
This commit is contained in:
rafael2k 2009-05-06 18:34:20 +00:00
parent fc5f17569d
commit e72af678ee
2 changed files with 23 additions and 2 deletions

View File

@ -215,12 +215,14 @@ TcpSocket :: open ( void ) throw ( Exception )
snprintf(portstr, sizeof(portstr), "%d", port);
if (getaddrinfo(host , portstr, &hints, &ptr)) {
sockfd = 0;
throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno);
}
memcpy ( addr, ptr->ai_addr, ptr->ai_addrlen);
freeaddrinfo(ptr);
#else
if ( !(pHostEntry = gethostbyname( host)) ) {
sockfd = 0;
throw Exception( __FILE__, __LINE__, "gethostbyname error", errno);
}
@ -231,6 +233,7 @@ TcpSocket :: open ( void ) throw ( Exception )
#endif
if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) {
sockfd = 0;
throw Exception( __FILE__, __LINE__, "socket error", errno);
}
@ -281,6 +284,8 @@ TcpSocket :: canRead ( unsigned int sec,
ret = pselect( sockfd + 1, &fdset, NULL, NULL, &timespec, &sigset);
if ( ret == -1 ) {
::close( sockfd);
sockfd = 0;
throw Exception( __FILE__, __LINE__, "select error");
}
@ -313,7 +318,9 @@ TcpSocket :: read ( void * buf,
break;
default:
throw Exception( __FILE__, __LINE__, "recv error", errno);
::close( sockfd);
sockfd = 0;
throw Exception( __FILE__, __LINE__, "recv error", errno);
}
}
@ -350,6 +357,8 @@ TcpSocket :: canWrite ( unsigned int sec,
ret = pselect( sockfd + 1, NULL, &fdset, NULL, &timespec, &sigset);
if ( ret == -1 ) {
::close( sockfd);
sockfd = 0;
throw Exception( __FILE__, __LINE__, "select error");
}
@ -380,6 +389,8 @@ TcpSocket :: write ( const void * buf,
if ( errno == EAGAIN ) {
ret = 0;
} else {
::close( sockfd);
sockfd = 0;
throw Exception( __FILE__, __LINE__, "send error", errno);
}
}

View File

@ -78,7 +78,17 @@ aacPlusEncoder :: open ( void )
reportEvent(1, "Using aacplus codec version", "720 3gpp");
bitrate = getOutBitrate() * 1000;
bandwidth = 0;
useParametricStereo = 0;
numAncDataBytes=0;
coreWriteOffset = 0;
envReadOffset = 0;
writeOffset = INPUT_DELAY*MAX_CHANNELS;
writtenSamples = 0;
aacEnc = NULL;
hEnvEnc=NULL;
/* set up basic parameters for aacPlus codec */
AacInitDefaultConfig(&config);
nChannelsAAC = nChannelsSBR = getOutChannel();