From ea8feac587158a314b061d52ae235205bab28992 Mon Sep 17 00:00:00 2001 From: Sion Chaudhuri Date: Tue, 30 Apr 2013 01:01:53 -0700 Subject: [PATCH] Free up resources allocated for audio when client connection is closed --- src/protocols/vnc/guac_handlers.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/protocols/vnc/guac_handlers.c b/src/protocols/vnc/guac_handlers.c index 2377e7b1..515caf5c 100644 --- a/src/protocols/vnc/guac_handlers.c +++ b/src/protocols/vnc/guac_handlers.c @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -46,6 +47,7 @@ #include "client.h" #include "convert.h" +#include "pa_handlers.h" int vnc_guac_client_handle_messages(guac_client* client) { @@ -124,6 +126,20 @@ int vnc_guac_client_free_handler(guac_client* client) { vnc_guac_client_data* guac_client_data = (vnc_guac_client_data*) client->data; rfbClient* rfb_client = guac_client_data->rfb_client; + if (guac_client_data->audio_enabled) { + + /* Wait for audio read and send threads to join */ + if (guac_client_data->audio_read_thread) + pthread_join(*(guac_client_data->audio_read_thread), NULL); + + if (guac_client_data->audio_send_thread) + pthread_join(*(guac_client_data->audio_send_thread), NULL); + + /* Free up buffer allocated for audio stream */ + if(guac_client_data->audio_buffer) + guac_pa_buffer_free(guac_client_data->audio_buffer); + } + /* Free encodings string, if used */ if (guac_client_data->encodings != NULL) free(guac_client_data->encodings);