Index: wiimote/util.c
===================================================================
--- wiimote/util.c	(revision a339960844acef82f06e6c4ba82575fafc4e50ac)
+++ wiimote/util.c	(revision 00aa4948876dc0530d8a1e5ab8170a9befa9f14c)
@@ -16,4 +16,7 @@
  *
  *  ChangeLog:
+ *  03/14/2007: L. Donnie Smith <cwiid@abstrakraft.org>
+ *  * audited error checking (coda and error handler sections)
+ *
  *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org>
  *  * created wiimote_err_func variable
@@ -164,5 +167,5 @@
 	 */
 	int dev_id;
-	int sock;
+	int sock = -1;
 	inquiry_info *dev_list = NULL;
 	int i;
@@ -174,9 +177,11 @@
 	if ((dev_id = hci_get_route(NULL)) == -1) {
 		wiimote_err(NULL, "No Bluetooth device found");
-		return -1;
+		ret = -1;
+		goto CODA;
 	}
 	if ((sock = hci_open_dev(dev_id)) == -1) {
 		wiimote_err(NULL, "Error opening Bluetooth device");
-		return -1;
+		ret = -1;
+		goto CODA;
 	}
 
@@ -185,6 +190,6 @@
 	                             IREQ_CACHE_FLUSH)) == -1) {
 		wiimote_err(NULL, "Error on device inquiry");
-		hci_close_dev(sock);
-		return -1;
+		ret = -1;
+		goto CODA;
 	}
 
@@ -206,5 +211,8 @@
 	}
 
-	hci_close_dev(sock);
+CODA:
+	if (sock != -1) {
+		hci_close_dev(sock);
+	}
 	if (dev_list) {
 		free(dev_list);
