Re: [PATCH spice-gtk 12/15] channel-main: file_xfer_failed -> file_xfer_completed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 03/10/2013 03:31 PM, Marc-André Lureau wrote:
Is that necessary? According to GInputStream doc: " Closing a stream
multiple times will not return an error."

Calling it twice won't return an error, but it will cause file_xfer_close_cb
to get called twice, and thus try to free the SpiceFileXferTask twice.

Regards,

Hans


On Sat, Mar 9, 2013 at 12:06 PM, Hans de Goede <hdegoede@xxxxxxxxxx> wrote:
Make file_xfer_failed usable for all file_stream closing and protect it
against double calls.

Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
---
  gtk/channel-main.c | 18 +++++++++++++-----
  1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/gtk/channel-main.c b/gtk/channel-main.c
index e4b9f9e..39061e9 100644
--- a/gtk/channel-main.c
+++ b/gtk/channel-main.c
@@ -55,6 +55,7 @@ typedef struct spice_migrate spice_migrate;
  #define FILE_XFER_CHUNK_SIZE (VD_AGENT_MAX_DATA_SIZE * 32)
  typedef struct SpiceFileXferTask {
      uint32_t                       id;
+    gboolean                       closed;
      GFile                          *file;
      SpiceMainChannel               *channel;
      GFileInputStream               *file_stream;
@@ -2585,17 +2586,24 @@ void spice_main_set_display_enabled(SpiceMainChannel *channel, int id, gboolean
      c->timer_id = g_timeout_add_seconds(1, timer_set_display, channel);
  }

-static void file_xfer_failed(SpiceFileXferTask *task, GError *error)
+static void file_xfer_completed(SpiceFileXferTask *task, GError *error)
  {
-    SPICE_DEBUG("File %s xfer failed: %s",
-                g_file_get_path(task->file), error->message);
+    if (task->closed) {
+        g_clear_error(&error);
+        return;
+    }

-    task->error = error;
+    if (error) {
+        SPICE_DEBUG("File %s xfer failed: %s",
+                    g_file_get_path(task->file), error->message);
+        task->error = error;
+    }
      g_input_stream_close_async(G_INPUT_STREAM(task->file_stream),
                                 G_PRIORITY_DEFAULT,
                                 task->cancellable,
                                 file_xfer_close_cb,
                                 task);
+    task->closed = TRUE;
  }

  static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res, gpointer data)
@@ -2646,7 +2654,7 @@ static void file_xfer_info_async_cb(GObject *obj, GAsyncResult *res, gpointer da
      return;

  failed:
-    file_xfer_failed(task, error);
+    file_xfer_completed(task, error);
  }

  static void file_xfer_read_async_cb(GObject *obj, GAsyncResult *res, gpointer data)
--
1.8.1.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel



_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]