[epiphany/mcatanzaro/#1773: 1/2] password-manager: Fix crash when deleting all passwords




commit ca3955b0ca486975bf9aacd979ffd82060f5fd7a
Author: Michael Catanzaro <mcatanzaro redhat com>
Date:   Fri May 6 16:43:12 2022 -0500

    password-manager: Fix crash when deleting all passwords
    
    This broke in 7d080a31. The callback here is not prepared for there to
    be no async data, but the async data is only required when clearing a
    single password, not when clearing all of them. At first, I adjusted the
    callback to handle both possibilities, but eventually decided that it's
    clearer to just have two separate callbacks.
    
    Fixes #1773

 lib/sync/ephy-password-manager.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/lib/sync/ephy-password-manager.c b/lib/sync/ephy-password-manager.c
index f8a15df77..493fd7439 100644
--- a/lib/sync/ephy-password-manager.c
+++ b/lib/sync/ephy-password-manager.c
@@ -735,20 +735,12 @@ secret_password_clear_cb (GObject      *source_object,
 
   secret_password_clear_finish (result, &error);
   if (error) {
-    if (data->task)
-      g_task_return_error (data->task, error);
-    else
-      g_warning ("Failed to clear secrets from password schema: %s", error->message);
-
+    g_task_return_error (data->task, error);
     manage_record_async_data_free (data);
-    return;
-  }
-
-  if (data->record)
+  } else {
     ephy_password_manager_store_record (data->manager, data->record);
-
-  if (data->task)
     g_task_return_boolean (data->task, TRUE);
+  }
 
   manage_record_async_data_free (data);
 }
@@ -842,6 +834,18 @@ ephy_password_manager_forget (EphyPasswordManager *self,
                                forget_cb, task);
 }
 
+static void
+clear_all_cb (GObject      *source_object,
+              GAsyncResult *result,
+              gpointer      user_data)
+{
+  g_autoptr (GError) error = NULL;
+
+  secret_password_clear_finish (result, &error);
+  if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+    g_warning ("Failed to clear secrets from password schema: %s", error->message);
+}
+
 static void
 forget_all_cb (GList    *records,
                gpointer  user_data)
@@ -851,7 +855,7 @@ forget_all_cb (GList    *records,
 
   attributes = secret_attributes_build (EPHY_FORM_PASSWORD_SCHEMA, NULL);
   secret_password_clearv (EPHY_FORM_PASSWORD_SCHEMA, attributes, NULL,
-                          (GAsyncReadyCallback)secret_password_clear_cb, NULL);
+                          (GAsyncReadyCallback)clear_all_cb, NULL);
 
   for (GList *l = records; l && l->data; l = l->next)
     g_signal_emit_by_name (self, "synchronizable-deleted", l->data);


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