From 2a56e0f073f98440aef347c50f540e5c22521520 Mon Sep 17 00:00:00 2001 From: darkeye Date: Fri, 2 Aug 2002 17:59:17 +0000 Subject: [PATCH] bug fix: when the last server dropped connection, darkice crashed --- darkice/trunk/ChangeLog | 2 ++ darkice/trunk/src/Connector.cpp | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index 1cc78b5..ef49fa0 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -1,5 +1,7 @@ DarkIce 0.11 + o bug fix: when the last server dropped connection, darkice crashed + thanks to Nicu Pavel o bug fix for LameLibEncoder: the mp3 encoding buffer was deleted too early, resulting in mp3 data corruption. thanks to Nicu Pavel diff --git a/darkice/trunk/src/Connector.cpp b/darkice/trunk/src/Connector.cpp index 5ad455e..65d33a1 100644 --- a/darkice/trunk/src/Connector.cpp +++ b/darkice/trunk/src/Connector.cpp @@ -164,6 +164,7 @@ Connector :: detach ( Sink * sink ) throw ( Exception ) sinks[0] = 0; delete[] sinks; sinks = 0; + --numSinks; return true; @@ -255,7 +256,6 @@ Connector :: transfer ( unsigned long bytes, { unsigned int u; unsigned long b; - unsigned char * buf = new unsigned char[bufSize]; if ( numSinks == 0 ) { return 0; @@ -265,6 +265,8 @@ Connector :: transfer ( unsigned long bytes, return 0; } + unsigned char * buf = new unsigned char[bufSize]; + reportEvent( 6, "Connector :: tranfer, bytes", bytes); for ( b = 0; !bytes || b < bytes; ) { @@ -288,9 +290,6 @@ Connector :: transfer ( unsigned long bytes, } catch ( Exception & e ) { sinks[u]->close(); detach( sinks[u].get() ); - /* with the call to detach, numSinks gets 1 lower, - * and the next sink comes to sinks[u] */ - --u; reportEvent( 4, "Connector :: transfer, sink removed, remaining", @@ -299,8 +298,12 @@ Connector :: transfer ( unsigned long bytes, if ( numSinks == 0 ) { reportEvent( 4, "Connector :: transfer, no more sinks"); - break; + delete[] buf; + return b; } + /* with the call to detach, numSinks gets 1 lower, + * and the next sink comes to sinks[u] */ + --u; } } } @@ -338,6 +341,9 @@ Connector :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.9 2002/08/02 17:59:17 darkeye + bug fix: when the last server dropped connection, darkice crashed + Revision 1.8 2002/07/20 16:37:06 darkeye added fault tolerance in case a server connection is dropped