From: Bruno Haible Date: Thu, 18 May 2017 23:38:48 +0000 (+0200) Subject: Fix memory leaks. X-Git-Tag: v0.20~460 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7594468edd5f7240107852b6ec4b41a863c4cca8;p=thirdparty%2Fgettext.git Fix memory leaks. 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. --- diff --git a/gettext-runtime/intl/loadmsgcat.c b/gettext-runtime/intl/loadmsgcat.c index 7dadda171..42465d19f 100644 --- a/gettext-runtime/intl/loadmsgcat.c +++ b/gettext-runtime/intl/loadmsgcat.c @@ -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; diff --git a/gettext-runtime/intl/localealias.c b/gettext-runtime/intl/localealias.c index f64f8cac5..87c84abed 100644 --- a/gettext-runtime/intl/localealias.c +++ b/gettext-runtime/intl/localealias.c @@ -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;