From e72af678ee83e3cba3601bd0e46e19c7d1013650 Mon Sep 17 00:00:00 2001 From: rafael2k Date: Wed, 6 May 2009 18:34:20 +0000 Subject: [PATCH] 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 --- darkice/branches/darkice-aacp/src/TcpSocket.cpp | 13 ++++++++++++- .../branches/darkice-aacp/src/aacPlusEncoder.cpp | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/darkice/branches/darkice-aacp/src/TcpSocket.cpp b/darkice/branches/darkice-aacp/src/TcpSocket.cpp index 745d08b..28046f4 100644 --- a/darkice/branches/darkice-aacp/src/TcpSocket.cpp +++ b/darkice/branches/darkice-aacp/src/TcpSocket.cpp @@ -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, ×pec, &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, ×pec, &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); } } diff --git a/darkice/branches/darkice-aacp/src/aacPlusEncoder.cpp b/darkice/branches/darkice-aacp/src/aacPlusEncoder.cpp index 7118865..9b71ccb 100644 --- a/darkice/branches/darkice-aacp/src/aacPlusEncoder.cpp +++ b/darkice/branches/darkice-aacp/src/aacPlusEncoder.cpp @@ -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();