From c3558bb8cd889e5b957190e9f5d23afad1e17b72 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Wed, 4 Jun 2008 11:35:24 -0700 Subject: [PATCH] XQuartz: Don't forget to destroy the mutex and cond after we're done with them --- hw/xquartz/mach-startup/bundle-main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c index 67c338f21..9a50668c3 100644 --- a/hw/xquartz/mach-startup/bundle-main.c +++ b/hw/xquartz/mach-startup/bundle-main.c @@ -203,15 +203,15 @@ static void socket_handoff_thread(void *arg) { fprintf(stderr, "Failed to create socket: %s - %s\n", filename, strerror(errno)); data->retval = EXIT_FAILURE; - pthread_mutex_unlock(&data->lock); pthread_cond_broadcast(&data->cond); + pthread_mutex_unlock(&data->lock); return; } /* Let the dispatch thread now tell the caller that we're ready */ data->retval = EXIT_SUCCESS; - pthread_mutex_unlock(&data->lock); pthread_cond_broadcast(&data->cond); + pthread_mutex_unlock(&data->lock); if(connect(handoff_fd, servaddr, servaddr_len) < 0) { fprintf(stderr, "Failed to connect to socket: %s - %s\n", filename, strerror(errno)); @@ -227,6 +227,7 @@ static void socket_handoff_thread(void *arg) { kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) { handoff_data_t handoff_data; + /* Initialize our data */ pthread_mutex_init(&handoff_data.lock, NULL); pthread_cond_init(&handoff_data.cond, NULL); strlcpy(handoff_data.socket_filename, socket_filename, STRING_T_SIZE); @@ -234,9 +235,15 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) { pthread_mutex_lock(&handoff_data.lock); create_thread(socket_handoff_thread, &handoff_data); - - pthread_cond_wait(&handoff_data.cond, &handoff_data.lock); + /* Wait for our return value */ + pthread_cond_wait(&handoff_data.cond, &handoff_data.lock); + pthread_mutex_unlock(&handoff_data.lock); + + /* Cleanup */ + pthread_cond_destroy(&handoff_data.cond); + pthread_mutex_destroy(&handoff_data.lock); + return handoff_data.retval; }