[Spice-devel] [spice-gtk v2 9/9] spicy: Fix spice_file_transfer_task_get_filename leak

Victor Toso victortoso at redhat.com
Tue Aug 2 09:48:50 UTC 2016


From: Christophe Fergeau <cfergeau at redhat.com>

It was wrongly annotated as (transfer none)

An alternative would be to store what is returned by
g_file_get_basename() in SpiceFileTransferTask and return that, this
would allow to make spice_file_transfer_task_get_filename() (transfer
none) without leaking memory.
---
 src/spice-file-transfer-task.c | 2 +-
 src/spicy.c                    | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/spice-file-transfer-task.c b/src/spice-file-transfer-task.c
index 4e51b7e..80191c9 100644
--- a/src/spice-file-transfer-task.c
+++ b/src/spice-file-transfer-task.c
@@ -536,7 +536,7 @@ void spice_file_transfer_task_cancel(SpiceFileTransferTask *self)
  *
  * Gets the name of the file being transferred in this task
  *
- * Returns: (transfer none): The basename of the file
+ * Returns: (transfer full): The basename of the file
  *
  * Since: 0.31
  **/
diff --git a/src/spicy.c b/src/spicy.c
index ea4d4e0..3cee7e5 100644
--- a/src/spicy.c
+++ b/src/spicy.c
@@ -1514,6 +1514,7 @@ task_cancel_cb(GtkButton *button,
 static TransferTaskWidgets *
 transfer_task_widgets_new(SpiceFileTransferTask *task)
 {
+    char *filename;
     TransferTaskWidgets *widgets = g_new0(TransferTaskWidgets, 1);
 
     widgets->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
@@ -1521,7 +1522,9 @@ transfer_task_widgets_new(SpiceFileTransferTask *task)
     widgets->cancel = gtk_button_new_with_label("Cancel");
 
     widgets->progress = gtk_progress_bar_new();
-    widgets->label = gtk_label_new(spice_file_transfer_task_get_filename(task));
+    filename = spice_file_transfer_task_get_filename(task);
+    widgets->label = gtk_label_new(filename);
+    g_free(filename);
 
     gtk_widget_set_halign(widgets->label, GTK_ALIGN_START);
     gtk_widget_set_valign(widgets->label, GTK_ALIGN_BASELINE);
-- 
2.7.4



More information about the Spice-devel mailing list