[xiph-commits] r11134 - icecast/trunk/libshout/src

msmith at svn.xiph.org msmith at svn.xiph.org
Thu Apr 13 15:30:56 PDT 2006


Author: msmith
Date: 2006-04-13 15:30:53 -0700 (Thu, 13 Apr 2006)
New Revision: 11134

Modified:
   icecast/trunk/libshout/src/shout.c
Log:
Don't let a failed shout_open() leave the shout_t in an inconsistent state.
Also fixes some leaks in failed shout_open() calls.

Fixed bug #833. Thanks to brendan for review, and _mx for prodding.


Modified: icecast/trunk/libshout/src/shout.c
===================================================================
--- icecast/trunk/libshout/src/shout.c	2006-04-13 22:22:24 UTC (rev 11133)
+++ icecast/trunk/libshout/src/shout.c	2006-04-13 22:30:53 UTC (rev 11134)
@@ -952,11 +952,13 @@
 			if ((rc = sock_connected(self->socket, 0)) < 1) {
 				if (!rc)
 					return SHOUTERR_BUSY;
-				else
-					return SHOUTERR_SOCKET;
+				else {
+                                        rc = SHOUTERR_SOCKET;
+                                        goto failure;
+                                }
 			}
 			if ((rc = create_request(self)) != SHOUTERR_SUCCESS)
-				return rc;
+                                goto failure;
 		}
 		self->state = SHOUT_STATE_REQ_PENDING;
 
@@ -964,36 +966,34 @@
 		do
 			rc = send_queue(self);
 		while (!shout_get_nonblocking(self) && rc == SHOUTERR_BUSY);
+                if (rc == SHOUTERR_BUSY)
+                        return rc;
 		if (rc != SHOUTERR_SUCCESS)
-			return rc;
+                        goto failure;
 		self->state = SHOUT_STATE_RESP_PENDING;
 
 	case SHOUT_STATE_RESP_PENDING:
 		do
 			rc = get_response(self);
 		while (!shout_get_nonblocking(self) && rc == SHOUTERR_BUSY);
+                if (rc == SHOUTERR_BUSY)
+                        return rc;
+
 		if (rc != SHOUTERR_SUCCESS)
-			return rc;
+                        goto failure;
 
 		if ((rc = parse_response(self)) != SHOUTERR_SUCCESS)
-			return rc;
+                        goto failure;
 
 		if (self->format == SHOUT_FORMAT_OGG) {
-			if ((self->error = shout_open_ogg(self)) != SHOUTERR_SUCCESS) {
-				self->state = SHOUT_STATE_UNCONNECTED;
-				sock_close(self->socket);
-				return self->error;
-			}
+			if ((rc = self->error = shout_open_ogg(self)) != SHOUTERR_SUCCESS)
+                                goto failure;
 		} else if (self->format == SHOUT_FORMAT_MP3) {
-			if ((self->error = shout_open_mp3(self)) != SHOUTERR_SUCCESS) {
-				self->state = SHOUT_STATE_UNCONNECTED;
-				sock_close(self->socket);
-				return self->error;
-			}
+			if ((rc = self->error = shout_open_mp3(self)) != SHOUTERR_SUCCESS)
+                                goto failure;
 		} else {
-			self->state = SHOUT_STATE_UNCONNECTED;
-			sock_close(self->socket);
-			return self->error = SHOUTERR_INSANE;
+                        rc = SHOUTERR_INSANE;
+                        goto failure;
 		}
 
 	case SHOUT_STATE_CONNECTED:
@@ -1001,6 +1001,10 @@
 	}
 	
 	return SHOUTERR_SUCCESS;
+
+failure:
+        shout_close(self);
+	return rc;
 }
 
 static int try_write (shout_t *self, const void *data, size_t len)



More information about the commits mailing list