diff options
author | Victor Toso <victortoso@redhat.com> | 2016-08-03 16:16:01 +0200 |
---|---|---|
committer | Victor Toso <victortoso@redhat.com> | 2016-08-10 13:58:51 +0200 |
commit | 5f0df31aec24f9eb5e829a5b367038f4b0ef9850 (patch) | |
tree | 2234a605c2662ccf14a4f0e401064598c264bc89 | |
parent | 27756bae62d6e6d9a64c396d7d21cf3c084130be (diff) |
file-transfer: improve GHashTable with value_destroy_func
By using g_hash_table_new_full() we can unref its value which is the
SpiceFileTransferTask. This makes the code a little bit simpler as
nowhere we use the xfer-task after removing it from hash table.
Acked-by: Pavel Grunt <pgrunt@redhat.com>
-rw-r--r-- | src/channel-main.c | 4 | ||||
-rw-r--r-- | src/spice-file-transfer-task.c | 2 |
2 files changed, 1 insertions, 5 deletions
diff --git a/src/channel-main.c b/src/channel-main.c index 47e19e1..a074928 100644 --- a/src/channel-main.c +++ b/src/channel-main.c @@ -2898,8 +2898,6 @@ static void file_transfer_operation_free(FileTransferOperation *xfer_op) g_task_return_boolean(xfer_op->task, TRUE); } g_object_unref(xfer_op->task); - - /* SpiceFileTransferTask itself is freed after it emits "finish" */ g_hash_table_unref(xfer_op->xfer_task); spice_debug("Freeing file-transfer-operation %p", xfer_op); @@ -2970,7 +2968,6 @@ static void file_transfer_operation_task_finished(SpiceFileTransferTask *xfer_ta /* Likely the operation has ended before the remove-task was called. One * situation that this can easily happen is if the agent is disconnected * while there are pending files. */ - g_object_unref(xfer_task); return; } @@ -2993,7 +2990,6 @@ static void file_transfer_operation_task_finished(SpiceFileTransferTask *xfer_ta /* Remove and free SpiceFileTransferTask */ g_hash_table_remove(xfer_op->xfer_task, GUINT_TO_POINTER(task_id)); - g_object_unref(xfer_task); /* Keep file_xfer_tasks up to date. If no more elements, operation is over */ g_hash_table_remove(channel->priv->file_xfer_tasks, GUINT_TO_POINTER(task_id)); diff --git a/src/spice-file-transfer-task.c b/src/spice-file-transfer-task.c index 58340e3..e7f50da 100644 --- a/src/spice-file-transfer-task.c +++ b/src/spice-file-transfer-task.c @@ -380,7 +380,7 @@ GHashTable *spice_file_transfer_task_create_tasks(GFile **files, g_return_val_if_fail(files != NULL && files[0] != NULL, NULL); - xfer_ht = g_hash_table_new(g_direct_hash, g_direct_equal); + xfer_ht = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref); for (i = 0; files[i] != NULL && !g_cancellable_is_cancelled(cancellable); i++) { SpiceFileTransferTask *xfer_task; guint32 task_id; |