diff --git a/server/dcc.cpp b/server/dcc.cpp index 606e6873..a825cf2d 100644 --- a/server/dcc.cpp +++ b/server/dcc.cpp @@ -571,7 +571,7 @@ void dcc_start(DisplayChannelClient *dcc) if (!display_channel_client_wait_for_init(dcc)) return; - g_object_ref(dcc); + dcc->ref(); dcc->ack_zero_messages_window(); if (display->priv->surfaces[0].context.canvas) { display_channel_current_flush(display, 0); @@ -588,7 +588,7 @@ void dcc_start(DisplayChannelClient *dcc) dcc->pipe_add(dcc_gl_scanout_item_new(dcc, NULL, 0)); dcc_push_monitors_config(dcc); } - g_object_unref(dcc); + dcc->unref(); } static void dcc_destroy_stream_agents(DisplayChannelClient *dcc) diff --git a/server/display-channel.cpp b/server/display-channel.cpp index 0bdda034..8d43de8a 100644 --- a/server/display-channel.cpp +++ b/server/display-channel.cpp @@ -1476,7 +1476,7 @@ bool display_channel_wait_for_migrate_data(DisplayChannel *display) rcc = (RedChannelClient*) g_list_nth_data(clients, 0); - g_object_ref(rcc); + rcc->ref(); for (;;) { rcc->receive(); if (!rcc->is_connected()) { @@ -1494,7 +1494,7 @@ bool display_channel_wait_for_migrate_data(DisplayChannel *display) } usleep(DISPLAY_CLIENT_RETRY_INTERVAL); } - g_object_unref(rcc); + rcc->unref(); return ret; } diff --git a/server/red-channel-client.cpp b/server/red-channel-client.cpp index b96c3d1a..b60b89d8 100644 --- a/server/red-channel-client.cpp +++ b/server/red-channel-client.cpp @@ -704,7 +704,7 @@ static void red_channel_client_ping_timer(void *opaque) { RedChannelClient *rcc = (RedChannelClient *) opaque; - g_object_ref(rcc); + rcc->ref(); spice_assert(rcc->priv->latency_monitor.state == PING_STATE_TIMER); red_channel_client_cancel_ping_timer(rcc); @@ -720,13 +720,13 @@ static void red_channel_client_ping_timer(void *opaque) if (so_unsent_size > 0) { /* tcp send buffer is still occupied. rescheduling ping */ red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS); - g_object_unref(rcc); + rcc->unref(); return; } #endif /* ifdef HAVE_LINUX_SOCKIOS_H */ /* More portable alternative code path (less accurate but avoids bogus ioctls)*/ red_channel_client_push_ping(rcc); - g_object_unref(rcc); + rcc->unref(); } static inline int red_channel_client_waiting_for_ack(RedChannelClient *rcc) @@ -758,7 +758,7 @@ static void red_channel_client_connectivity_timer(void *opaque) RedChannelClientConnectivityMonitor *monitor = &rcc->priv->connectivity_monitor; int is_alive = TRUE; - g_object_ref(rcc); + rcc->ref(); if (monitor->state == CONNECTIVITY_STATE_BLOCKED) { if (!monitor->received_bytes && !monitor->sent_bytes) { @@ -798,7 +798,7 @@ static void red_channel_client_connectivity_timer(void *opaque) rcc, monitor->timeout); rcc->disconnect(); } - g_object_unref(rcc); + rcc->unref(); } void RedChannelClient::start_connectivity_monitoring(uint32_t timeout_ms) @@ -842,14 +842,14 @@ static void red_channel_client_event(int fd, int event, void *data) { RedChannelClient *rcc = (RedChannelClient *) data; - g_object_ref(rcc); + rcc->ref(); if (event & SPICE_WATCH_EVENT_READ) { rcc->receive(); } if (event & SPICE_WATCH_EVENT_WRITE) { rcc->push(); } - g_object_unref(rcc); + rcc->unref(); } static uint32_t full_header_get_msg_size(SpiceDataHeaderOpaque *header) @@ -1285,16 +1285,16 @@ static void red_channel_client_handle_incoming(RedChannelClient *rcc) void RedChannelClient::receive() { - g_object_ref(this); + ref(); red_channel_client_handle_incoming(this); - g_object_unref(this); + unref(); } void RedChannelClient::send() { - g_object_ref(this); + ref(); red_channel_client_handle_outgoing(this); - g_object_unref(this); + unref(); } static inline RedPipeItem *red_channel_client_pipe_item_get(RedChannelClient *rcc) @@ -1315,7 +1315,7 @@ void RedChannelClient::push() } priv->during_send = TRUE; - g_object_ref(this); + ref(); if (is_blocked()) { send(); } @@ -1349,7 +1349,7 @@ void RedChannelClient::push() red_stream_flush(priv->stream); } priv->during_send = FALSE; - g_object_unref(this); + unref(); } int RedChannelClient::get_roundtrip_ms() const diff --git a/server/red-channel-client.h b/server/red-channel-client.h index 2de62569..102074ec 100644 --- a/server/red-channel-client.h +++ b/server/red-channel-client.h @@ -137,6 +137,9 @@ struct RedChannelClient: public GObject void block_read(); void unblock_read(); + void ref() { g_object_ref(this); } + void unref() { g_object_unref(this); } + RedChannelClientPrivate *priv; }; diff --git a/server/red-channel.cpp b/server/red-channel.cpp index 70d82ec2..2a04e5c1 100644 --- a/server/red-channel.cpp +++ b/server/red-channel.cpp @@ -28,6 +28,7 @@ #include "red-stream.h" #include "main-dispatcher.h" #include "utils.h" +#include "utils.hpp" /* * Lifetime of RedChannel, RedChannelClient and RedClient: @@ -721,7 +722,7 @@ static void handle_dispatcher_migrate(void *opaque, void *payload) RedChannelClass *klass = RED_CHANNEL_GET_CLASS(channel); klass->migrate(msg->rcc); - g_object_unref(msg->rcc); + msg->rcc->unref(); } void RedChannel::migrate_client(RedChannelClient *rcc) @@ -733,7 +734,7 @@ void RedChannel::migrate_client(RedChannelClient *rcc) return; } - RedMessageMigrate payload = { .rcc = (RedChannelClient *) g_object_ref(rcc) }; + RedMessageMigrate payload = { .rcc = red::add_ref(rcc) }; dispatcher_send_message_custom(priv->dispatcher, handle_dispatcher_migrate, &payload, sizeof(payload), false); } diff --git a/server/red-client.cpp b/server/red-client.cpp index bccea554..fc3f996c 100644 --- a/server/red-client.cpp +++ b/server/red-client.cpp @@ -106,7 +106,10 @@ red_client_finalize (GObject *object) { RedClient *self = RED_CLIENT(object); - g_clear_object(&self->mcc); + if (self->mcc) { + self->mcc->unref(); + self->mcc = nullptr; + } spice_debug("release client=%p", self); pthread_mutex_destroy(&self->lock); @@ -233,7 +236,7 @@ void red_client_destroy(RedClient *client) spice_assert(rcc->pipe_is_empty()); spice_assert(rcc->no_item_being_sent()); - g_object_unref(rcc); + rcc->unref(); pthread_mutex_lock(&client->lock); } pthread_mutex_unlock(&client->lock); @@ -293,8 +296,10 @@ gboolean red_client_add_channel(RedClient *client, RedChannelClient *rcc, GError // first must be the main one if (!client->mcc) { - spice_assert(MAIN_CHANNEL_CLIENT(rcc) != NULL); - client->mcc = (MainChannelClient *) g_object_ref(rcc); + // FIXME use dynamic_cast to check type + // spice_assert(MAIN_CHANNEL_CLIENT(rcc) != NULL); + rcc->ref(); + client->mcc = (MainChannelClient *) rcc; } client->channels = g_list_prepend(client->channels, rcc); if (client->during_target_migrate && client->seamless_migrate) { @@ -351,7 +356,7 @@ void red_client_remove_channel(RedChannelClient *rcc) } pthread_mutex_unlock(&client->lock); if (link) { - g_object_unref(rcc); + rcc->unref(); } }