[gnome-software: 2/3] gs-age-rating-context-dialog: Clear attribute and row state with widgets




commit 51517c5b9475b3d1f534b8842c263146f6ef8c45
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Mar 10 13:56:04 2022 +0000

    gs-age-rating-context-dialog: Clear attribute and row state with widgets
    
    When clearing the widget state, also clear the internal lists of
    attributes and rows, otherwise `self->rows` continues to point to freed
    widgets (which were in `self->attributes_list`), and `self->attributes`
    continues to cause `add_attribute_row()` to think the row widgets still
    exist.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #1678

 src/gs-age-rating-context-dialog.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-age-rating-context-dialog.c b/src/gs-age-rating-context-dialog.c
index 6266149b2..090c0b542 100644
--- a/src/gs-age-rating-context-dialog.c
+++ b/src/gs-age-rating-context-dialog.c
@@ -989,8 +989,17 @@ update_attributes_list (GsAgeRatingContextDialog *self)
        gboolean is_unknown;
        g_autofree gchar *title = NULL;
 
+       /* Clear existing state. */
        gs_widget_remove_all (GTK_WIDGET (self->attributes_list), (GsRemoveFunc) gtk_list_box_remove);
 
+       for (GsAgeRatingGroupType group_type = 0; group_type < GS_AGE_RATING_GROUP_TYPE_COUNT; group_type++) {
+               g_list_free_full (self->attributes[group_type],
+                                 (GDestroyNotify) gs_age_rating_attribute_free);
+               self->attributes[group_type] = NULL;
+
+               self->rows[group_type] = NULL;
+       }
+
        /* UI state is undefined if app is not set. */
        if (self->app == NULL)
                return;
@@ -1142,19 +1151,6 @@ gs_age_rating_context_dialog_dispose (GObject *object)
        G_OBJECT_CLASS (gs_age_rating_context_dialog_parent_class)->dispose (object);
 }
 
-static void
-gs_age_rating_context_dialog_finalize (GObject *object)
-{
-       GsAgeRatingContextDialog *self = GS_AGE_RATING_CONTEXT_DIALOG (object);
-
-       for (GsAgeRatingGroupType group_type = 0; group_type < GS_AGE_RATING_GROUP_TYPE_COUNT; group_type++) {
-               g_list_free_full (self->attributes[group_type],
-                                 (GDestroyNotify) gs_age_rating_attribute_free);
-       }
-
-       G_OBJECT_CLASS (gs_age_rating_context_dialog_parent_class)->finalize (object);
-}
-
 static void
 gs_age_rating_context_dialog_class_init (GsAgeRatingContextDialogClass *klass)
 {
@@ -1164,7 +1160,6 @@ gs_age_rating_context_dialog_class_init (GsAgeRatingContextDialogClass *klass)
        object_class->get_property = gs_age_rating_context_dialog_get_property;
        object_class->set_property = gs_age_rating_context_dialog_set_property;
        object_class->dispose = gs_age_rating_context_dialog_dispose;
-       object_class->finalize = gs_age_rating_context_dialog_finalize;
 
        /**
         * GsAgeRatingContextDialog:app: (nullable)


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