diff options
| author | Johan Hedberg <johan.hedberg@nokia.com> | 2009-03-12 11:44:38 -0300 | 
|---|---|---|
| committer | Johan Hedberg <johan.hedberg@nokia.com> | 2009-03-12 11:44:38 -0300 | 
| commit | 1f393331ef64660e614cb21be347b7bebfcff2ed (patch) | |
| tree | 377d6ea0ed90b492fb3bdd9a71d979c7b764f5e6 | |
| parent | c4c03a457df6ad3708bf6abc8ad0a9d7edf3b454 (diff) | |
Fix audio plugin initialization failure cases
| -rw-r--r-- | audio/main.c | 21 | ||||
| -rw-r--r-- | audio/manager.c | 11 | ||||
| -rw-r--r-- | audio/unix.c | 6 | 
3 files changed, 27 insertions, 11 deletions
diff --git a/audio/main.c b/audio/main.c index c3b5bb56..1678b58d 100644 --- a/audio/main.c +++ b/audio/main.c @@ -128,23 +128,32 @@ static int audio_init(void)  	if (unix_init() < 0) {  		error("Unable to setup unix socket"); -		return -EIO; +		goto failed;  	} -	if (audio_manager_init(connection, config) < 0) { -		dbus_connection_unref(connection); -		return -EIO; -	} +	if (audio_manager_init(connection, config) < 0) +		goto failed;  	sco_server = bt_io_listen(BT_IO_SCO, sco_server_cb, NULL, NULL,  					NULL, NULL,  					BT_IO_OPT_INVALID);  	if (!sco_server) {  		error("Unable to start SCO server socket"); -		return -EIO; +		goto failed;  	}  	return 0; + +failed: +	audio_manager_exit(); +	unix_exit(); + +	if (connection) { +		dbus_connection_unref(connection); +		connection = NULL; +	} + +	return -EIO;  }  static void audio_exit(void) diff --git a/audio/manager.c b/audio/manager.c index fd0e6f62..2e48654a 100644 --- a/audio/manager.c +++ b/audio/manager.c @@ -982,10 +982,17 @@ proceed:  void audio_manager_exit(void)  { +	/* Bail out early if we haven't been initialized */ +	if (connection == NULL) +		return; +  	dbus_connection_unref(connection); +	connection = NULL; -	if (config) +	if (config) {  		g_key_file_free(config); +		config = NULL; +	}  	if (enabled.headset) {  		btd_unregister_adapter_driver(&headset_server_driver); @@ -1002,8 +1009,6 @@ void audio_manager_exit(void)  		btd_unregister_adapter_driver(&avrcp_server_driver);  	btd_unregister_device_driver(&audio_driver); - -	connection = NULL;  }  struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interface, diff --git a/audio/unix.c b/audio/unix.c index 575617b3..e455c4e3 100644 --- a/audio/unix.c +++ b/audio/unix.c @@ -1275,6 +1275,8 @@ void unix_exit(void)  {  	g_slist_foreach(clients, (GFunc) client_free, NULL);  	g_slist_free(clients); -	close(unix_sock); -	unix_sock = -1; +	if (unix_sock >= 0) { +		close(unix_sock); +		unix_sock = -1; +	}  }  | 
