gdbusprivate: Clarify GDBusMessage ownership transfers

Add g_steal_pointer() and g_clear_object() calls in various places to
clarify the ownership transfers for GDBusMessage instances, in a bid to
understand what’s going on in this code and to try to find a
use-after-finalize problem.

This introduces no functional changes, but hopefully makes the code a
little clearer.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2019-04-12 16:56:04 +01:00
parent 96aa2e34b3
commit 1fbf82be17

View File

@ -492,9 +492,9 @@ _g_dbus_worker_emit_message_about_to_be_sent (GDBusWorker *worker,
{
GDBusMessage *ret;
if (!g_atomic_int_get (&worker->stopped))
ret = worker->message_about_to_be_sent_callback (worker, message, worker->user_data);
ret = worker->message_about_to_be_sent_callback (worker, g_steal_pointer (&message), worker->user_data);
else
ret = message;
ret = g_steal_pointer (&message);
return ret;
}
@ -506,13 +506,13 @@ _g_dbus_worker_queue_or_deliver_received_message (GDBusWorker *worker,
if (worker->frozen || g_queue_get_length (worker->received_messages_while_frozen) > 0)
{
/* queue up */
g_queue_push_tail (worker->received_messages_while_frozen, message);
g_queue_push_tail (worker->received_messages_while_frozen, g_steal_pointer (&message));
}
else
{
/* not frozen, nor anything in queue */
_g_dbus_worker_emit_message_received (worker, message);
g_object_unref (message);
g_clear_object (&message);
}
}
@ -529,7 +529,7 @@ unfreeze_in_idle_cb (gpointer user_data)
while ((message = g_queue_pop_head (worker->received_messages_while_frozen)) != NULL)
{
_g_dbus_worker_emit_message_received (worker, message);
g_object_unref (message);
g_clear_object (&message);
}
worker->frozen = FALSE;
}
@ -796,7 +796,7 @@ _g_dbus_worker_do_read_cb (GInputStream *input_stream,
}
/* yay, got a message, go deliver it */
_g_dbus_worker_queue_or_deliver_received_message (worker, message);
_g_dbus_worker_queue_or_deliver_received_message (worker, g_steal_pointer (&message));
/* start reading another message! */
worker->read_buffer_bytes_wanted = 0;