From 43c6bf91b7c53ee9f93f7ea1cead5bba94c61f88 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Thu, 5 Mar 2020 13:01:27 +0000 Subject: [PATCH] reds: Remove a weak pointer usage RedCharDevice can all be removed just calling unref, beside the agent that needs special threatment. Signed-off-by: Frediano Ziglio --- server/char-device.h | 1 - server/reds.cpp | 23 ++++++----------------- server/smartcard.cpp | 7 ------- server/smartcard.h | 1 - server/spicevmc.cpp | 7 ------- 5 files changed, 6 insertions(+), 33 deletions(-) diff --git a/server/char-device.h b/server/char-device.h index 686cc7a9..75b6765d 100644 --- a/server/char-device.h +++ b/server/char-device.h @@ -242,7 +242,6 @@ void red_char_device_write_buffer_release(RedCharDevice *dev, RedCharDevice *spicevmc_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin, uint8_t channel_type); -void spicevmc_device_disconnect(SpiceCharDeviceInstance *char_device); SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice *dev); diff --git a/server/reds.cpp b/server/reds.cpp index df20f38e..71d68ee0 100644 --- a/server/reds.cpp +++ b/server/reds.cpp @@ -3201,8 +3201,7 @@ static void reds_add_char_device(RedsState *reds, RedCharDevice *dev) reds->char_devices = g_list_append(reds->char_devices, dev); } -static void reds_on_char_device_destroy(RedsState *reds, - RedCharDevice *dev) +static void reds_remove_char_device(RedsState *reds, RedCharDevice *dev) { g_return_if_fail(reds != NULL); g_warn_if_fail(g_list_find(reds->char_devices, dev) != NULL); @@ -3252,9 +3251,6 @@ spice_server_char_device_add_interface(SpiceServer *reds, SpiceBaseInstance *sin * just a sanity check to ensure that assumption is correct */ spice_assert(dev_state == char_device->st); - g_object_weak_ref(G_OBJECT(dev_state), - (GWeakNotify)reds_on_char_device_destroy, - reds); /* setting the char_device state to "started" for backward compatibily with * qemu releases that don't call spice api for start/stop (not implemented yet) */ if (reds->vm_running) { @@ -3281,19 +3277,12 @@ static int spice_server_char_device_remove_interface(RedsState *reds, SpiceBaseI red_char_device_reset_dev_instance(reds->agent_dev, NULL); } } -#ifdef USE_SMARTCARD - else if (strcmp(char_device->subtype, SUBTYPE_SMARTCARD) == 0) { - smartcard_device_disconnect(char_device); - } -#endif - else if (strcmp(char_device->subtype, SUBTYPE_USBREDIR) == 0 || - strcmp(char_device->subtype, SUBTYPE_PORT) == 0) { - spicevmc_device_disconnect(char_device); - } else { - spice_warning("failed to remove char device %s", char_device->subtype); - } - char_device->st = NULL; + if (char_device->st) { + reds_remove_char_device(reds, char_device->st); + char_device->st->unref(); + char_device->st = NULL; + } return 0; } diff --git a/server/smartcard.cpp b/server/smartcard.cpp index 82aace56..00399c11 100644 --- a/server/smartcard.cpp +++ b/server/smartcard.cpp @@ -242,13 +242,6 @@ static RedCharDeviceSmartcard *smartcard_device_new(RedsState *reds, SpiceCharDe return dev; } -void smartcard_device_disconnect(SpiceCharDeviceInstance *char_device) -{ - g_return_if_fail(RED_IS_CHAR_DEVICE_SMARTCARD(char_device->st)); - - char_device->st->unref(); -} - RedCharDevice *smartcard_device_connect(RedsState *reds, SpiceCharDeviceInstance *char_device) { RedCharDeviceSmartcard *dev; diff --git a/server/smartcard.h b/server/smartcard.h index e1d0b016..8f8ab2ae 100644 --- a/server/smartcard.h +++ b/server/smartcard.h @@ -44,7 +44,6 @@ struct RedCharDeviceSmartcardClass: public RedCharDeviceClass * connect to smartcard interface, used by smartcard channel */ RedCharDevice *smartcard_device_connect(RedsState *reds, SpiceCharDeviceInstance *char_device); -void smartcard_device_disconnect(SpiceCharDeviceInstance *char_device); void smartcard_channel_write_to_reader(RedCharDeviceWriteBuffer *write_buf); SpiceCharDeviceInstance* smartcard_readers_get(uint32_t reader_id); SpiceCharDeviceInstance *smartcard_readers_get_unattached(void); diff --git a/server/spicevmc.cpp b/server/spicevmc.cpp index bdb295a5..577b34f8 100644 --- a/server/spicevmc.cpp +++ b/server/spicevmc.cpp @@ -688,13 +688,6 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds, return dev; } -/* Must be called from RedClient handling thread. */ -void spicevmc_device_disconnect(SpiceCharDeviceInstance *sin) -{ - sin->st->unref(); - sin->st = NULL; -} - static void spicevmc_port_event(RedCharDevice *char_dev, uint8_t event) { RedVmcChannel *channel;