[Spice-devel] [spice-gtk v1 08/10] file-transfer: increase reference for channel-main

Christophe Fergeau cfergeau at redhat.com
Mon Aug 1 10:46:43 UTC 2016


On Sat, Jul 30, 2016 at 12:26:29AM +0200, Victor Toso wrote:
> channel-main uses the SpiceFileTransferTask reference given in the
> hash table provided by spice_file_transfer_task_create_tasks(). That
> means SpiceFileTransferTask is not holding a reference for itself but
> it relies on it due the async calls it provides.
> 
> This patch increases the reference of each SpiceFileTransferTask for
> the hash table which will be unref'ed by channel-main in
> file_transfer_operation_task_finished(); the original reference is
> kept to SpiceFileTransferTask to be freed after the finish signal is
> emitted on spice_file_transfer_task_close_stream_cb().
> 
> This patch fixes some critical warnings as we have two g_object_unref
> but only one reference.
> ---
>  src/spice-file-transfer-task.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/spice-file-transfer-task.c b/src/spice-file-transfer-task.c
> index ca1b51d..8ebd256 100644
> --- a/src/spice-file-transfer-task.c
> +++ b/src/spice-file-transfer-task.c
> @@ -304,6 +304,7 @@ void spice_file_transfer_task_completed(SpiceFileTransferTask *self,
>      self->pending = TRUE;
>  signal:
>      g_signal_emit(self, task_signals[SIGNAL_FINISHED], 0, self->error);
> +    /* SpiceFileTransferTask unref is done after inpust stream is closed */

typo: s/inpust/input/

>  }
>  
>  G_GNUC_INTERNAL
> @@ -374,7 +375,7 @@ GHashTable *spice_file_transfer_task_create_tasks(GFile **files,
>          xfer_task->flags = flags;
>  
>          task_id = spice_file_transfer_task_get_id(xfer_task);
> -        g_hash_table_insert(xfer_ht, GUINT_TO_POINTER(task_id), xfer_task);
> +        g_hash_table_insert(xfer_ht, GUINT_TO_POINTER(task_id), g_object_ref(xfer_task));

I'd change the hash table creation to g_hash_table_new_full() so that
the unref() is done automatically on destroy.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160801/3ea408a4/attachment-0001.sig>


More information about the Spice-devel mailing list