[glade/tintou/valgrind-leaks: 2/2] Couple of fixes for memory leaks found with valgrind



commit f46af86c6edbdf473da9101bb9418ee62ae79c3e
Author: Corentin Noël <corentin noel collabora com>
Date:   Tue May 7 10:02:57 2019 +0200

    Couple of fixes for memory leaks found with valgrind
    
    Most of them are unfreed string and missed GList elements.

 gladeui/glade-editor-property.c |  4 +++-
 gladeui/glade-project.c         |  5 ++++-
 gladeui/glade-signal-model.c    | 12 ++++++++----
 gladeui/glade-utils.c           |  2 ++
 gladeui/glade-widget-adaptor.c  |  5 +++++
 gladeui/glade-xml-utils.c       |  5 ++---
 plugins/gtk+/glade-model-data.c |  3 ++-
 src/glade-window.c              | 21 +++++++++++----------
 8 files changed, 37 insertions(+), 20 deletions(-)
---
diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c
index e4dc39d9..40625f52 100644
--- a/gladeui/glade-editor-property.c
+++ b/gladeui/glade-editor-property.c
@@ -2921,12 +2921,13 @@ glade_eprop_object_populate_view_real (GtkTreeStore *model,
 
           if (good_type || has_decendant)
             {
+              gchar *prop_name = glade_eprop_object_name (widget_name, model, parent_iter);
               gtk_tree_store_append (model, &iter, parent_iter);
               gtk_tree_store_set
                   (model, &iter,
                    OBJ_COLUMN_WIDGET, widget,
                    OBJ_COLUMN_WIDGET_NAME,
-                   glade_eprop_object_name (widget_name, model, parent_iter),
+                   prop_name,
                    OBJ_COLUMN_WIDGET_CLASS, glade_widget_adaptor_get_title (adaptor),
                    /* Selectable if its a compatible type and
                     * its not itself.
@@ -2935,6 +2936,7 @@ glade_eprop_object_populate_view_real (GtkTreeStore *model,
                    good_type && !search_list (exception_widgets, widget),
                    OBJ_COLUMN_SELECTED,
                    good_type && search_list (selected_widgets, widget), -1);
+              g_free (prop_name);
             }
 
           if (has_decendant &&
diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c
index 987476fa..4f6db6d9 100644
--- a/gladeui/glade-project.c
+++ b/gladeui/glade-project.c
@@ -1961,6 +1961,7 @@ glade_project_check_target_version (GladeProject *project)
   GtkWidget *dialog;
   GString *text;
   GList *l;
+  gchar *project_name;
 
   glade_project_get_target_version (project, "gtk+", &major, &minor);
     
@@ -2010,12 +2011,14 @@ glade_project_check_target_version (GladeProject *project)
   else 
     text = NULL;
 
+  project_name = glade_project_get_name (project);
   dialog = gtk_message_dialog_new (GTK_WINDOW (glade_app_get_window ()),
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
                                    PROJECT_TARGET_DIALOG_TITLE_FMT,
-                                   glade_project_get_name (project),
+                                   project_name,
                                    major, minor);
+  g_free (project_name);
 
   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                             _("But this version of Glade is for GTK+ 3 only.\n"
diff --git a/gladeui/glade-signal-model.c b/gladeui/glade-signal-model.c
index 9e9b1b6a..977810e5 100644
--- a/gladeui/glade-signal-model.c
+++ b/gladeui/glade-signal-model.c
@@ -523,6 +523,8 @@ glade_signal_model_get_path (GtkTreeModel *model, GtkTreeIter *iter)
               break;
             }
         }
+
+      g_list_free (signals);
       return gtk_tree_path_new_from_indices (index0, index1, -1);
     }
   else if (widget)
@@ -663,12 +665,10 @@ glade_signal_model_iter_next_signal (GladeSignalModel *sig_model,
       glade_signal_model_create_signal_iter (sig_model, widget,
                                              next_handler,
                                              iter);
-      g_list_free (signal);
       return TRUE;
     }
   else
     {
-      g_list_free (signal);
       return FALSE;
     }
 }
@@ -703,7 +703,9 @@ glade_signal_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
                                                  glade_signal_class_get_name (sig_class));
       if (glade_signal_model_is_dummy_handler (sig_model, handler))
         {
-          return glade_signal_model_iter_next_signal (sig_model, widget, iter, signal);
+          gboolean ret = glade_signal_model_iter_next_signal (sig_model, widget, iter, signal);
+          g_list_free (signals);
+          return ret;
         }
       else if (handlers)
         {
@@ -730,7 +732,9 @@ glade_signal_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
             }
           else
             {
-              return glade_signal_model_iter_next_signal (sig_model, widget, iter, signal);
+              gboolean ret = glade_signal_model_iter_next_signal (sig_model, widget, iter, signal);
+              g_list_free (signals);
+              return ret;
             }
         }
       else
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 3d5cadfc..0e0560c7 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1050,6 +1050,8 @@ glade_util_have_devhelp (void)
             }
           else
             g_warning ("devhelp had bad return code: '%d'", ret);
+
+          g_free (ptr);
         }
       else
         {
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index a528da4f..1b610bfb 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -2900,6 +2900,10 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
    */
   if (adaptor->priv->type != adaptor->priv->real_type)
     {
+      if (adaptor->priv->signals)
+        g_list_free_full (adaptor->priv->signals,
+                          (GDestroyNotify) glade_signal_class_free);
+
       adaptor->priv->signals = gwa_list_signals (adaptor, adaptor->priv->real_type);
 
       gwa_update_properties_from_type (adaptor, adaptor->priv->real_type,
@@ -2912,6 +2916,7 @@ glade_widget_adaptor_from_catalog (GladeCatalog *catalog,
   if (adaptor->priv->generic_name == NULL)
     adaptor->priv->generic_name = g_strdup ("widget");
 
+  g_clear_pointer (&adaptor->priv->catalog, g_free);
   adaptor->priv->catalog = g_strdup (glade_catalog_get_name (catalog));
 
   if (glade_catalog_get_book (catalog))
diff --git a/gladeui/glade-xml-utils.c b/gladeui/glade-xml-utils.c
index f980bf85..8bcb8304 100644
--- a/gladeui/glade-xml-utils.c
+++ b/gladeui/glade-xml-utils.c
@@ -161,13 +161,12 @@ static gchar *
 glade_xml_get_value (xmlNodePtr node, const gchar *name)
 {
   xmlNodePtr child;
-  gchar *ret = NULL;
 
   for (child = node->children; child; child = child->next)
     if (!xmlStrcmp (child->name, BAD_CAST (name)))
-      ret = claim_string (xmlNodeGetContent (child));
+      return claim_string (xmlNodeGetContent (child));
 
-  return ret;
+  return NULL;
 }
 
 /**
diff --git a/plugins/gtk+/glade-model-data.c b/plugins/gtk+/glade-model-data.c
index 4a0b7d94..6adb389a 100644
--- a/plugins/gtk+/glade-model-data.c
+++ b/plugins/gtk+/glade-model-data.c
@@ -534,7 +534,7 @@ eprop_model_data_generate_store (GladeEditorProperty *eprop)
   GtkListStore *store = NULL;
   GladeModelData *iter_data;
   GNode *data_tree = NULL, *iter_node, *row_node;
-  GArray *gtypes = g_array_new (FALSE, TRUE, sizeof (GType));
+  GArray *gtypes = NULL;
   GtkTreeIter iter;
   gint column_num, row_num;
   GType index_type = G_TYPE_INT, string_type = G_TYPE_STRING, pointer_type = G_TYPE_POINTER;
@@ -546,6 +546,7 @@ eprop_model_data_generate_store (GladeEditorProperty *eprop)
     return NULL;
 
   /* Generate store with tailored column types */
+  gtypes = g_array_new (FALSE, TRUE, sizeof (GType));
   g_array_append_val (gtypes, index_type);
   for (iter_node = data_tree->children->children; iter_node;
        iter_node = iter_node->next)
diff --git a/src/glade-window.c b/src/glade-window.c
index c290a399..253ff961 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -140,26 +140,27 @@ refresh_title (GladeWindow *window)
   if (GLADE_WINDOW_ACTIVE_VIEW (window))
     {
       GladeProject *project = glade_design_view_get_project (GLADE_WINDOW_ACTIVE_VIEW (window));
-      gchar *title, *name = NULL;
+      gchar *title;
       GList *p;
 
       gtk_header_bar_set_custom_title (window->priv->headerbar, NULL);
 
-      name = glade_project_get_name (project);
-
+      title = glade_project_get_name (project);
       if (glade_project_get_modified (project))
-        name = g_strdup_printf ("*%s", name);
-      else
-        name = g_strdup (name);
+        {
+          gchar *old_title = g_steal_pointer (&title);
+          title = g_strdup_printf ("*%s", old_title);
+          g_free (old_title);
+        }
 
       if (glade_project_get_readonly (project) != FALSE)
-        title = g_strdup_printf ("%s %s", name, READONLY_INDICATOR);
-      else
-        title = g_strdup_printf ("%s", name);
+        {
+          gchar *old_title = g_steal_pointer (&title);
+          title = g_strdup_printf ("%s %s", old_title, READONLY_INDICATOR);
+        }
 
       gtk_header_bar_set_title (window->priv->headerbar, title);
       g_free (title);
-      g_free (name);
 
       if ((p = glade_app_get_projects ()) && g_list_next (p))
         gtk_header_bar_set_custom_title (window->priv->headerbar, window->priv->project_switcher);


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