core: Fix manager_cleanup order

This patch fixes the order in which things are cleaned up in
manager_cleanup. The profiles need to be cleaned up first (since they
are higher level constructs than adapters and devices) and we cannot
remove the adapter from the manager list before calling adapter_remove
since functions within adapter_remove may remove service records which
in turn relies on having the adapter present in the manager list.
diff --git a/src/manager.c b/src/manager.c
index 80b26e4..07f9482 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -245,16 +245,16 @@
 
 void manager_cleanup(const char *path)
 {
+	btd_profile_cleanup();
+
 	while (adapters) {
 		struct btd_adapter *adapter = adapters->data;
 
-		adapters = g_slist_remove(adapters, adapter);
 		adapter_remove(adapter);
+		adapters = g_slist_remove(adapters, adapter);
 		btd_adapter_unref(adapter);
 	}
 
-	btd_profile_cleanup();
-
 	btd_start_exit_timer();
 
 	g_dbus_unregister_interface(btd_get_dbus_connection(),