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:
parent
fc5f17569d
commit
e72af678ee
|
@ -215,12 +215,14 @@ TcpSocket :: open ( void ) throw ( Exception )
|
||||||
snprintf(portstr, sizeof(portstr), "%d", port);
|
snprintf(portstr, sizeof(portstr), "%d", port);
|
||||||
|
|
||||||
if (getaddrinfo(host , portstr, &hints, &ptr)) {
|
if (getaddrinfo(host , portstr, &hints, &ptr)) {
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno);
|
throw Exception( __FILE__, __LINE__, "getaddrinfo error", errno);
|
||||||
}
|
}
|
||||||
memcpy ( addr, ptr->ai_addr, ptr->ai_addrlen);
|
memcpy ( addr, ptr->ai_addr, ptr->ai_addrlen);
|
||||||
freeaddrinfo(ptr);
|
freeaddrinfo(ptr);
|
||||||
#else
|
#else
|
||||||
if ( !(pHostEntry = gethostbyname( host)) ) {
|
if ( !(pHostEntry = gethostbyname( host)) ) {
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "gethostbyname error", errno);
|
throw Exception( __FILE__, __LINE__, "gethostbyname error", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,6 +233,7 @@ TcpSocket :: open ( void ) throw ( Exception )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) {
|
if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) {
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "socket error", errno);
|
throw Exception( __FILE__, __LINE__, "socket error", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +284,8 @@ TcpSocket :: canRead ( unsigned int sec,
|
||||||
ret = pselect( sockfd + 1, &fdset, NULL, NULL, ×pec, &sigset);
|
ret = pselect( sockfd + 1, &fdset, NULL, NULL, ×pec, &sigset);
|
||||||
|
|
||||||
if ( ret == -1 ) {
|
if ( ret == -1 ) {
|
||||||
|
::close( sockfd);
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "select error");
|
throw Exception( __FILE__, __LINE__, "select error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +318,8 @@ TcpSocket :: read ( void * buf,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
::close( sockfd);
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "recv error", errno);
|
throw Exception( __FILE__, __LINE__, "recv error", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,6 +357,8 @@ TcpSocket :: canWrite ( unsigned int sec,
|
||||||
ret = pselect( sockfd + 1, NULL, &fdset, NULL, ×pec, &sigset);
|
ret = pselect( sockfd + 1, NULL, &fdset, NULL, ×pec, &sigset);
|
||||||
|
|
||||||
if ( ret == -1 ) {
|
if ( ret == -1 ) {
|
||||||
|
::close( sockfd);
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "select error");
|
throw Exception( __FILE__, __LINE__, "select error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,6 +389,8 @@ TcpSocket :: write ( const void * buf,
|
||||||
if ( errno == EAGAIN ) {
|
if ( errno == EAGAIN ) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
|
::close( sockfd);
|
||||||
|
sockfd = 0;
|
||||||
throw Exception( __FILE__, __LINE__, "send error", errno);
|
throw Exception( __FILE__, __LINE__, "send error", errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,16 @@ aacPlusEncoder :: open ( void )
|
||||||
|
|
||||||
reportEvent(1, "Using aacplus codec version", "720 3gpp");
|
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 */
|
/* set up basic parameters for aacPlus codec */
|
||||||
AacInitDefaultConfig(&config);
|
AacInitDefaultConfig(&config);
|
||||||
|
|
Loading…
Reference in New Issue