bluetooth: Release transport in stop_thread()
authorMikel Astiz <mikel.astiz@bmw-carit.de>
Fri, 28 Sep 2012 15:45:30 +0000 (17:45 +0200)
committerTanu Kaskinen <tanuk@iki.fi>
Sun, 14 Oct 2012 16:31:40 +0000 (19:31 +0300)
Avoid duplicated code by releasing the transport inside stop_thread(),
along with the rest of the thread-related cleanup.

src/modules/bluetooth/module-bluetooth-device.c

index 0f39772..e55c8c6 100644 (file)
@@ -1987,13 +1987,6 @@ static int setup_transport(struct userdata *u) {
         return -1;
     }
 
-    /* release transport if exist */
-    if (u->transport) {
-        bt_transport_release(u);
-        pa_xfree(u->transport);
-        u->transport = NULL;
-    }
-
     /* check if profile has a transport */
     t = pa_bluetooth_device_get_transport(d, u->profile);
     if (t == NULL) {
@@ -2066,6 +2059,12 @@ static void stop_thread(struct userdata *u) {
         u->hsp.nrec_changed_slot = NULL;
     }
 
+    if (u->transport) {
+        bt_transport_release(u);
+        pa_xfree(u->transport);
+        u->transport = NULL;
+    }
+
     if (u->sink) {
         if (u->profile == PROFILE_HSP) {
             k = pa_sprintf_malloc("bluetooth-device@%p", (void*) u->sink);
@@ -2230,12 +2229,6 @@ static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
 
     stop_thread(u);
 
-    if (u->profile != PROFILE_OFF && u->transport) {
-        bt_transport_release(u);
-        pa_xfree(u->transport);
-        u->transport = NULL;
-    }
-
     if (USE_SCO_OVER_PCM(u))
         restore_sco_volume_callbacks(u);
 
@@ -2740,11 +2733,6 @@ void pa__done(pa_module *m) {
     pa_xfree(u->address);
     pa_xfree(u->path);
 
-    if (u->transport) {
-        bt_transport_release(u);
-        pa_xfree(u->transport);
-    }
-
     if (u->discovery)
         pa_bluetooth_discovery_unref(u->discovery);