OSDN Git Service

bluez a2dp - destroy thread resources at exit
authorIan Kent <raven@themaw.net>
Mon, 28 Sep 2009 15:47:44 +0000 (23:47 +0800)
committerNick Pelly <npelly@google.com>
Wed, 30 Sep 2009 00:08:28 +0000 (17:08 -0700)
The dynamically created pthread mutex and condition variables
consume pthread resources. They should be destroyed prior to
freeing the structure containing them.

audio/liba2dp.c

index d7cab1b..5c4ef51 100755 (executable)
@@ -934,6 +934,16 @@ static int wait_for_start(struct bluetooth_data *data, int timeout)
        return -err;
 }
 
+static void a2dp_free(struct bluetooth_data *data)
+{
+       pthread_cond_destroy(&data->client_wait);
+       pthread_cond_destroy(&data->thread_wait);
+       pthread_cond_destroy(&data->thread_start);
+       pthread_mutex_destroy(&data->mutex);
+       free(data);
+       return;
+}
+
 static void* a2dp_thread(void *d)
 {
        struct bluetooth_data* data = (struct bluetooth_data*)d;
@@ -992,7 +1002,7 @@ static void* a2dp_thread(void *d)
                        case A2DP_CMD_QUIT:
                                bluetooth_close(data);
                                sbc_finish(&data->sbc);
-                               free(data);
+                               a2dp_free(data);
                                goto done;
 
                        default:
@@ -1064,7 +1074,7 @@ int a2dp_init(int rate, int channels, a2dpData* dataPtr)
 error:
        bluetooth_close(data);
        sbc_finish(&data->sbc);
-       free(data);
+       a2dp_free(data);
 
        return err;
 }