Encoding selector: fix memory leak
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 30 Aug 2015 15:06:15 +0000 (17:06 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 30 Aug 2015 15:31:14 +0000 (17:31 +0200)
src/ui/gui/psppire-encoding-selector.c

index 5b2d082b10a8a444b96776a3573b6742c183bfcb..536f3a595243ff8cb7459833dccf44f6cf4a8b80 100644 (file)
@@ -191,9 +191,9 @@ gchar *
 psppire_encoding_selector_get_encoding (GtkWidget *selector)
 {
   gchar *encoding = NULL;
-  GList *list, *pos;
+  GList *pos;
+  GList *list = gtk_container_get_children (GTK_CONTAINER (selector));
 
-  list = gtk_container_get_children (GTK_CONTAINER (selector));
   for (pos = list; pos; pos = pos->next)
     {
       GtkWidget *widget = pos->data;
@@ -210,7 +210,14 @@ psppire_encoding_selector_get_encoding (GtkWidget *selector)
           break;
         }
     }
+
   g_list_free (list);
 
-  return encoding && !strcmp (encoding, "Auto") ? NULL : encoding;
+  if (0 == strcmp (encoding, "Auto"))
+    {
+      g_free (encoding);
+      return NULL;
+    }
+
+  return encoding;
 }