[pango/asan-fixes: 4/4] tests: Fix some more memory errors




commit 867151e1f211e2c24cede98fc4c868217968ce5a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 12 13:56:19 2020 -0400

    tests: Fix some more memory errors
    
    test-break was leaking memory in various places,
    in particular when tests are skipped.

 tests/test-break.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/tests/test-break.c b/tests/test-break.c
index 0773e5d2..c4359643 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -62,7 +62,6 @@ test_file (const gchar *filename, GString *string)
 
   length = strlen (test);
   len = g_utf8_strlen (test, -1) + 1;
-  attrs = g_new (PangoLogAttr, len);
 
   pango_parse_markup (test, -1, 0, &attributes, &text, NULL, &error);
   g_assert_no_error (error);
@@ -79,6 +78,10 @@ test_file (const gchar *filename, GString *string)
       g_test_skip (msg);
       g_free (msg);
 #endif
+      g_free (contents);
+      g_object_unref (layout);
+      pango_attr_list_unref (attributes);
+      g_free (text);
       return FALSE;
     }
 
@@ -225,6 +228,7 @@ test_file (const gchar *filename, GString *string)
   g_object_unref (layout);
   g_free (attrs);
   g_free (contents);
+  g_free (text);
   pango_attr_list_unref (attributes);
 
   return TRUE;
@@ -255,7 +259,7 @@ test_break (gconstpointer d)
   GString *dump;
   gchar *diff;
 
-  const char *old_locale = setlocale (LC_ALL, NULL);
+  char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
   setlocale (LC_ALL, "en_US.utf8");
   if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
     {
@@ -265,20 +269,26 @@ test_break (gconstpointer d)
       g_test_skip (msg);
       g_free (msg);
 #endif
+      g_free (old_locale);
       return;
     }
 
-  expected_file = get_expected_filename (filename);
-
   dump = g_string_sized_new (0);
 
   if (!test_file (filename, dump))
-    return;
+    {
+      g_free (old_locale);
+      g_string_free (dump, TRUE);
+      return;
+    }
+
+  expected_file = get_expected_filename (filename);
 
   diff = diff_with_file (expected_file, dump->str, dump->len, &error);
   g_assert_no_error (error);
 
   setlocale (LC_ALL, old_locale);
+  g_free (old_locale);
 
   if (diff && diff[0])
     {


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