]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix memory leaks.
authorBruno Haible <bruno@clisp.org>
Thu, 18 May 2017 23:38:48 +0000 (01:38 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 18 May 2017 23:38:48 +0000 (01:38 +0200)
Found by Coverity.

* gettext-runtime/intl/loadmsgcat.c (_nl_load_domain): Free allocated memory
before returning in out-of-memory case.
* gettext-runtime/intl/localealias.c (relocate2): Define fallback.
(read_alias_file): Invoke relocate2 instead of relocate. Free the allocated
memory.

gettext-runtime/intl/loadmsgcat.c
gettext-runtime/intl/localealias.c

index 7dadda1713d6460cee841cfcc6a668eacfa1be55..42465d19f0107efaba6e20d7d08ff3a6590966ed 100644 (file)
@@ -1,5 +1,5 @@
 /* Load needed message catalogs.
-   Copyright (C) 1995-2016 Free Software Foundation, Inc.
+   Copyright (C) 1995-2017 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -914,7 +914,15 @@ _nl_load_domain (struct loaded_l10nfile *domain_file,
 
   domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
   if (domain == NULL)
-    goto out;
+    {
+#ifdef HAVE_MMAP
+      if (use_mmap)
+       munmap ((caddr_t) data, size);
+      else
+#endif
+       free (data);
+      goto out;
+    }
   domain_file->data = domain;
 
   domain->data = (char *) data;
index f64f8cac5cfc572f7b8bfa1bc209c15bb4b1d44e..87c84abed82a503cbbb51d3ebbd974b7ed4721fb 100644 (file)
@@ -1,5 +1,5 @@
 /* Handle aliases for locale names.
-   Copyright (C) 1995-2016 Free Software Foundation, Inc.
+   Copyright (C) 1995-2017 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -64,6 +64,7 @@ char *alloca ();
 # include "relocatable.h"
 #else
 # define relocate(pathname) (pathname)
+# define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
 #endif
 
 /* @@ end of prolog @@ */
@@ -219,6 +220,7 @@ read_alias_file (const char *fname, int fname_len)
 {
   FILE *fp;
   char *full_fname;
+  char *malloc_full_fname;
   size_t added;
   static const char aliasfile[] = "/locale.alias";
 
@@ -234,10 +236,11 @@ read_alias_file (const char *fname, int fname_len)
 #ifdef _LIBC
   /* Note the file is opened with cancellation in the I/O functions
      disabled.  */
-  fp = fopen (relocate (full_fname), "rce");
+  fp = fopen (relocate2 (full_fname, &malloc_full_fname), "rce");
 #else
-  fp = fopen (relocate (full_fname), "r");
+  fp = fopen (relocate2 (full_fname, &malloc_full_fname), "r");
 #endif
+  free (malloc_full_fname);
   freea (full_fname);
   if (fp == NULL)
     return 0;