diff --git a/src/protocols/rdp/guac_handlers.c b/src/protocols/rdp/guac_handlers.c index 7e99d195..f0ecdd79 100644 --- a/src/protocols/rdp/guac_handlers.c +++ b/src/protocols/rdp/guac_handlers.c @@ -68,8 +68,6 @@ int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed); int rdp_guac_client_free_handler(guac_client* client) { - guac_common_list_element* current; - rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; @@ -88,18 +86,7 @@ int rdp_guac_client_free_handler(guac_client* client) { if (guac_client_data->filesystem != NULL) guac_rdp_fs_free(guac_client_data->filesystem); - /* Free any allocated SVCs */ - current = guac_client_data->available_svc->head; - while (current != NULL) { - - guac_common_list_element* next = current->next; - - guac_rdp_free_svc((guac_rdp_svc*) current->data); - guac_common_list_remove(guac_client_data->available_svc, current); - - current = next; - - } + /* Free SVC list */ guac_common_list_free(guac_client_data->available_svc); /* Free client data */ diff --git a/src/protocols/rdp/guac_svc/svc_service.c b/src/protocols/rdp/guac_svc/svc_service.c index 39997724..f21870d7 100644 --- a/src/protocols/rdp/guac_svc/svc_service.c +++ b/src/protocols/rdp/guac_svc/svc_service.c @@ -106,7 +106,18 @@ void guac_svc_process_connect(rdpSvcPlugin* plugin) { } void guac_svc_process_terminate(rdpSvcPlugin* plugin) { + + /* Get corresponding guac_rdp_svc */ + guac_svcPlugin* svc_plugin = (guac_svcPlugin*) plugin; + guac_rdp_svc* svc = svc_plugin->svc; + + /* Remove and free SVC */ + guac_client_log_info(svc->client, "Closing channel \"%s\"...", svc->name); + guac_rdp_remove_svc(svc->client, svc->name); + free(svc); + free(plugin); + } void guac_svc_process_event(rdpSvcPlugin* plugin, wMessage* event) { diff --git a/src/protocols/rdp/rdp_svc.c b/src/protocols/rdp/rdp_svc.c index 24ab9b0a..53b30989 100644 --- a/src/protocols/rdp/rdp_svc.c +++ b/src/protocols/rdp/rdp_svc.c @@ -90,3 +90,32 @@ guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name) { } +guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, const char* name) { + + rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data; + guac_common_list_element* current; + guac_rdp_svc* found = NULL; + + /* For each available SVC */ + guac_common_list_lock(client_data->available_svc); + current = client_data->available_svc->head; + while (current != NULL) { + + /* If name matches, remove entry */ + guac_rdp_svc* current_svc = (guac_rdp_svc*) current->data; + if (strcmp(current_svc->name, name) == 0) { + guac_common_list_remove(client_data->available_svc, current); + found = current_svc; + break; + } + + current = current->next; + + } + guac_common_list_unlock(client_data->available_svc); + + /* Return removed entry, if any */ + return found; + +} + diff --git a/src/protocols/rdp/rdp_svc.h b/src/protocols/rdp/rdp_svc.h index 2c389bb7..7f8b5fbc 100644 --- a/src/protocols/rdp/rdp_svc.h +++ b/src/protocols/rdp/rdp_svc.h @@ -84,5 +84,10 @@ void guac_rdp_add_svc(guac_client* client, guac_rdp_svc* svc); */ guac_rdp_svc* guac_rdp_get_svc(guac_client* client, const char* name); +/** + * Remove the SVC with the given name from the list stored in the client. + */ +guac_rdp_svc* guac_rdp_remove_svc(guac_client* client, const char* name); + #endif