[grilo-plugins] lua-factory: Fix possible crash when fetch ops are cancelled



commit a051aa0e682ca699a240996876eb419cf5da18b3
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 30 01:00:39 2016 +0100

    lua-factory: Fix possible crash when fetch ops are cancelled
    
    When an operation was cancelled, we would go to free our operation data
    straight away, including struct members shared with other operations.
    
    As those could be on-going, and we know that the operations data members
    that are private to our operation are valid, go check whether we are the
    last operation, and only free the shared resources in that case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=773789

 src/lua-factory/grl-lua-library.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index f5cabb5..eff8ff3 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -480,12 +480,13 @@ grl_util_fetch_done (GObject *source_object,
   lua_State *L = fo->L;
   OperationSpec *os = fo->os;
   gchar *fixed = NULL;
+  gboolean cancelled = FALSE;
 
   if (!grl_net_wc_request_finish (GRL_NET_WC (source_object),
                                   res, &data, &len, &err)) {
     if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
       GRL_DEBUG ("fetch operation was cancelled");
-      goto free_fetch_op;
+      cancelled = TRUE;
     }
     data = NULL;
   } else if (!g_utf8_validate(data, len, NULL)) {
@@ -503,7 +504,8 @@ grl_util_fetch_done (GObject *source_object,
   g_free (fixed);
 
   if (err != NULL) {
-    GRL_WARNING ("Can't fetch element %d (URL: %s): '%s'", fo->index + 1, fo->url, err->message);
+    if (!cancelled)
+      GRL_WARNING ("Can't fetch element %d (URL: %s): '%s'", fo->index + 1, fo->url, err->message);
     g_clear_error (&err);
   } else {
     GRL_DEBUG ("fetch_done element %d of %d urls", fo->index + 1, fo->num_urls);
@@ -520,6 +522,9 @@ grl_util_fetch_done (GObject *source_object,
     }
   }
 
+  if (cancelled)
+    goto free_fetch_op;
+
   /* get the callback from the registry */
   lua_rawgeti (L, LUA_REGISTRYINDEX, fo->lua_callback);
 


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