bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] localename-tests: memory allocation fixes


From: Paul Eggert
Subject: [PATCH] localename-tests: memory allocation fixes
Date: Sun, 13 Mar 2016 22:45:56 -0700

* tests/test-localename.c (test_locale_name)
(test_locale_name_thread): Don't call freelocale on a locale
that was the base of a successful newlocale, as that
results in a double free.  Problem reported by Assaf Gordon.
(test_locale_name_thread): Free saved names after use, to pacify
gcc -fsanitize=address.
---
 ChangeLog               | 10 ++++++++++
 tests/test-localename.c | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0b1639e..317c50a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-03-13  Paul Eggert  <address@hidden>
+
+       localename-tests: memory allocation fixes
+       * tests/test-localename.c (test_locale_name)
+       (test_locale_name_thread): Don't call freelocale on a locale
+       that was the base of a successful newlocale, as that
+       results in a double free.  Problem reported by Assaf Gordon.
+       (test_locale_name_thread): Free saved names after use, to pacify
+       gcc -fsanitize=address.
+
 2016-03-08  Paul Eggert  <address@hidden>
 
        intprops: make .h file license match module
diff --git a/tests/test-localename.c b/tests/test-localename.c
index a61fa2c..be8fcaf 100644
--- a/tests/test-localename.c
+++ b/tests/test-localename.c
@@ -200,7 +200,9 @@ test_locale_name (void)
         if (loc != NULL)
           {
             locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
-            if (locale != NULL)
+            if (locale == NULL)
+              freelocale (loc);
+            else
               {
                 unsigned int j;
 
@@ -217,7 +219,6 @@ test_locale_name (void)
                 uselocale (LC_GLOBAL_LOCALE);
                 freelocale (locale);
               }
-            freelocale (loc);
           }
       }
   }
@@ -267,7 +268,9 @@ test_locale_name_thread (void)
         if (loc != NULL)
           {
             locale_t locale = newlocale (category_mask, "de_DE.UTF-8", loc);
-            if (locale != NULL)
+            if (locale == NULL)
+              freelocale (loc);
+            else
               {
                 unsigned int j;
 
@@ -285,7 +288,6 @@ test_locale_name_thread (void)
                 uselocale (LC_GLOBAL_LOCALE);
                 freelocale (locale);
               }
-            freelocale (loc);
           }
       }
   }
@@ -464,7 +466,10 @@ test_locale_name_thread (void)
           unsigned int i;
 
           for (i = 0; i < SIZEOF (categories); i++)
-            ASSERT (strcmp (unsaved_names[j][i], saved_names[j][i]) == 0);
+            {
+              ASSERT (strcmp (unsaved_names[j][i], saved_names[j][i]) == 0);
+              free (saved_names[j][i]);
+            }
         }
   }
 #else
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]