This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix memory leak in loadarchive.c (BZ #1318)


Hi!

_nl_normalize_codeset returns a freshly malloced string no matter whether
the original string has been already normalized or not.  So we should free
it always, not only when it has not been normalized before.
$ LC_ALL=en_US.UTF-8 valgrind /bin/echo 2>&1 | grep definitely
$ LC_ALL=en_US.utf8 valgrind /bin/echo 2>&1 | grep definitely
==28320==    definitely lost: 5 bytes in 1 blocks.

2005-09-09  Jakub Jelinek  <jakub@redhat.com>

	[BZ #1318]
	* locale/loadarchive.c (_nl_load_locale_from_archive): Free
	normalized_codeset even if p was already normalized.
	Reported by Jaroslav Snajdr <jsnajdr@kerio.com>.

--- libc/locale/loadarchive.c.jj	2003-09-14 20:13:40.000000000 +0200
+++ libc/locale/loadarchive.c	2005-09-09 18:05:25.000000000 +0200
@@ -1,5 +1,5 @@
 /* Code to load locale data from the locale archive file.
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -185,9 +185,9 @@ _nl_load_locale_from_archive (int catego
 	    memcpy (__mempcpy (__mempcpy (newname, name, p - name),
 			       normalized_codeset, normlen),
 		    rest, restlen);
-	    free ((char *) normalized_codeset);
 	    name = newname;
 	  }
+	free ((char *) normalized_codeset);
       }
   }
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]