This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Fix mbsrtowcs + uselocale leaks
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Roland McGrath <roland at redhat dot com>, Ulrich Drepper <drepper at redhat dot com>, Benjamin Kosnik <bkoz at redhat dot com>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Tue, 5 Nov 2002 20:01:07 +0100
- Subject: [PATCH] Fix mbsrtowcs + uselocale leaks
- References: <20021105111727.051ffcb4.bkoz@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Nov 05, 2002 at 11:17:27AM -0600, Benjamin Kosnik wrote:
> This is representative of the last memory-type issue for the C++
> libraries. It has to do with using mbsrtowcs and named locales.
>
> In the code below, if the mbsrtowcs block is active without the
> uselocale/freelocale blocks below, no leaks. If just the uselocale/free
> locale blocks are active without the mbsrtowcs block, no leaks.
>
> If both are active, then
>
> ==25125== LEAK SUMMARY:
> ==25125== definitely lost: 16 bytes in 1 blocks.
> ==25125== possibly lost: 0 bytes in 0 blocks.
> ==25125== still reachable: 936 bytes in 7 blocks.
>
> I'm running valgrind like so:
>
> #!/bin/bash
>
> FILE=$1
> FLAGS="-v --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes"
>
> valgrind $FLAGS $FILE
>
>
> This is on RH 8.0, with gcc-3_2-branch compilers and Jakub's
> glibc-2.3.1-2 rpms.
I don't have valgrind installed, so I just fixed what I saw in
mtrace output.
The gconv_dl.c change is needed because _nl_archive_subfreeres may well run
after gconv_dl's free_mem and it was segfaulting otherwise.
2002-11-05 Jakub Jelinek <jakub@redhat.com>
* iconv/gconv_dl.c (free_mem): Clear loaded.
* locale/loadarchive.c (_nl_archive_subfreeres): Call locale_data's
cleanup if any.
--- libc/iconv/gconv_dl.c.jj 2002-10-29 12:18:27.000000000 +0100
+++ libc/iconv/gconv_dl.c 2002-11-05 20:02:35.000000000 +0100
@@ -206,6 +206,7 @@ do_release_all (void *nodep)
libc_freeres_fn (free_mem)
{
__tdestroy (loaded, do_release_all);
+ loaded = NULL;
}
--- libc/locale/loadarchive.c.jj 2002-10-29 12:25:28.000000000 +0100
+++ libc/locale/loadarchive.c 2002-11-05 19:47:31.000000000 +0100
@@ -510,8 +510,12 @@ _nl_archive_subfreeres (void)
free (dead->name);
for (category = 0; category < __LC_LAST; ++category)
if (category != LC_ALL)
- /* _nl_unload_locale just does this free for the archive case. */
- free (dead->data[category]);
+ {
+ /* _nl_unload_locale just does this free for the archive case. */
+ if (dead->data[category]->private.cleanup)
+ (*dead->data[category]->private.cleanup) (dead->data[category]);
+ free (dead->data[category]);
+ }
free (dead);
}
archloaded = NULL;
Jakub