[Spice-devel] [PATCH spice-gtk 1/2] vmcstream: fix task cancellation
Jakub Janků
jjanku at redhat.com
Tue Aug 20 14:05:46 UTC 2019
If the task is cancelled, g_task_propagate_pointer()
in spice_vmc_output_stream_write_finish() returns NULL
which produces following errors:
(spicy:13597): GSpice-CRITICAL **: 15:39:46.168: spice_vmc_write_finish: assertion 'result != NULL' failed
(spicy:13597): GLib-GObject-CRITICAL **: 15:39:46.168: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
To fix this, call spice_vmc_write_finish() immediately in the
corresponding write_cb().
Signed-off-by: Jakub Janků <jjanku at redhat.com>
---
src/vmcstream.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/src/vmcstream.c b/src/vmcstream.c
index b6f6d1a..b7da103 100644
--- a/src/vmcstream.c
+++ b/src/vmcstream.c
@@ -397,18 +397,11 @@ spice_vmc_output_stream_write_fn(GOutputStream *stream,
static gssize
spice_vmc_output_stream_write_finish(GOutputStream *stream,
- GAsyncResult *simple,
+ GAsyncResult *result,
GError **error)
{
- SpiceVmcOutputStream *self = SPICE_VMC_OUTPUT_STREAM(stream);
- GAsyncResult *res = g_task_propagate_pointer(G_TASK(simple), error);
- gssize bytes_written;
-
- SPICE_DEBUG("spicevmc write finish");
- bytes_written = spice_vmc_write_finish(self->channel, res, error);
- g_object_unref(res);
-
- return bytes_written;
+ g_return_val_if_fail(g_task_is_valid(result, stream), -1);
+ return g_task_propagate_int(G_TASK(result), error);
}
static void
@@ -417,9 +410,17 @@ write_cb(GObject *source_object,
gpointer user_data)
{
GTask *task = user_data;
+ GError *error = NULL;
+ gssize bytes_written;
- g_task_return_pointer(task, g_object_ref(res), g_object_unref);
+ SPICE_DEBUG("spicevmc write finish");
+ bytes_written = spice_vmc_write_finish(SPICE_CHANNEL(source_object), res, &error);
+ if (error) {
+ g_task_return_error(task, error);
+ } else {
+ g_task_return_int(task, bytes_written);
+ }
g_object_unref(task);
}
--
2.21.0
More information about the Spice-devel
mailing list