]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Avoid memory leak upon realloc failure.
authorBruno Haible <bruno@clisp.org>
Tue, 20 Apr 2004 11:06:47 +0000 (11:06 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:51 +0000 (12:11 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/localcharset.c
gettext-tools/lib/ChangeLog
gettext-tools/lib/localcharset.c

index b5a48df56a9f4e09471108a247e5c9d08bb525b3..fb26f4fd33d2ffeddb724bb39f936edda7c90218 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-20  Jim Meyering  <jim@meyering.net>
+            Bruno Haible  <bruno@clisp.org>
+
+       * localcharset.c (get_charset_aliases) [!VMS && !WIN32]: Don't leak
+       memory when realloc fails.
+
 2004-03-02  Bruno Haible  <bruno@clisp.org>
 
        * localename.c (_nl_locale_name): Add info about default territory for
index 4865f1037a06f09c76a35fd3060c55359e95790e..82a4b191423f55464533d99c17080479b9c4103f 100644 (file)
@@ -1,6 +1,6 @@
 /* Determine a canonical name for the current locale's character encoding.
 
-   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 2000-2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published
@@ -141,15 +141,17 @@ get_charset_aliases ()
       else
        {
          /* Parse the file's contents.  */
-         int c;
-         char buf1[50+1];
-         char buf2[50+1];
          char *res_ptr = NULL;
          size_t res_size = 0;
-         size_t l1, l2;
 
          for (;;)
            {
+             int c;
+             char buf1[50+1];
+             char buf2[50+1];
+             size_t l1, l2;
+             char *old_res_ptr;
+
              c = getc (fp);
              if (c == EOF)
                break;
@@ -170,6 +172,7 @@ get_charset_aliases ()
                break;
              l1 = strlen (buf1);
              l2 = strlen (buf2);
+             old_res_ptr = res_ptr;
              if (res_size == 0)
                {
                  res_size = l1 + 1 + l2 + 1;
@@ -184,6 +187,8 @@ get_charset_aliases ()
                {
                  /* Out of memory. */
                  res_size = 0;
+                 if (old_res_ptr != NULL)
+                   free (old_res_ptr);
                  break;
                }
              strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
index 84db04e634b6031db41375822d474e0357e1b412..7333cb92a58915f94c1aff14838036ac5c1b2aa6 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-20  Jim Meyering  <jim@meyering.net>
+            Bruno Haible  <bruno@clisp.org>
+
+       * localcharset.c (get_charset_aliases) [!VMS && !WIN32]: Don't leak
+       memory when realloc fails.
+
 2004-03-18  Paul Eggert  <eggert@twinsun.com>
             Bruno Haible  <bruno@clisp.org>
 
index 4865f1037a06f09c76a35fd3060c55359e95790e..82a4b191423f55464533d99c17080479b9c4103f 100644 (file)
@@ -1,6 +1,6 @@
 /* Determine a canonical name for the current locale's character encoding.
 
-   Copyright (C) 2000-2003 Free Software Foundation, Inc.
+   Copyright (C) 2000-2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published
@@ -141,15 +141,17 @@ get_charset_aliases ()
       else
        {
          /* Parse the file's contents.  */
-         int c;
-         char buf1[50+1];
-         char buf2[50+1];
          char *res_ptr = NULL;
          size_t res_size = 0;
-         size_t l1, l2;
 
          for (;;)
            {
+             int c;
+             char buf1[50+1];
+             char buf2[50+1];
+             size_t l1, l2;
+             char *old_res_ptr;
+
              c = getc (fp);
              if (c == EOF)
                break;
@@ -170,6 +172,7 @@ get_charset_aliases ()
                break;
              l1 = strlen (buf1);
              l2 = strlen (buf2);
+             old_res_ptr = res_ptr;
              if (res_size == 0)
                {
                  res_size = l1 + 1 + l2 + 1;
@@ -184,6 +187,8 @@ get_charset_aliases ()
                {
                  /* Out of memory. */
                  res_size = 0;
+                 if (old_res_ptr != NULL)
+                   free (old_res_ptr);
                  break;
                }
              strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);