PATCH: Fix localedata/tst-leaks.c
H . J . Lu
hjl@lucon.org
Thu Jun 28 13:19:00 GMT 2001
This patch seems to fix localedata/tst-leaks.c. The problem is we
free locale `data' twice. I don't know what is the best way.
H.J.
----
2001-06-28 H.J. Lu <hjl@gnu.org>
* locale/findlocale.c (locale_file_list): Renamed to ...
(_nl_locale_file_list): This. Make it extern.
(free_mem): Move to ...
* locale/setlocale.c (free_mem): Here.
--- locale/findlocale.c.unload Thu Jun 28 12:17:24 2001
+++ locale/findlocale.c Thu Jun 28 13:08:46 2001
@@ -36,7 +36,7 @@ extern struct locale_data *const _nl_C[]
/* For each category we keep a list of records for the locale files
which are somehow addressed. */
-static struct loaded_l10nfile *locale_file_list[__LC_LAST];
+struct loaded_l10nfile *_nl_locale_file_list[__LC_LAST];
struct locale_data *
@@ -118,7 +118,7 @@ _nl_find_locale (const char *locale_path
/* If exactly this locale was already asked for we have an entry with
the complete name. */
- locale_file = _nl_make_l10nflist (&locale_file_list[category],
+ locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
locale_path, locale_path_len, mask,
language, territory, codeset,
normalized_codeset, modifier, special,
@@ -129,7 +129,7 @@ _nl_find_locale (const char *locale_path
{
/* Find status record for addressed locale file. We have to search
through all directories in the locale path. */
- locale_file = _nl_make_l10nflist (&locale_file_list[category],
+ locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
locale_path, locale_path_len, mask,
language, territory, codeset,
normalized_codeset, modifier, special,
@@ -251,7 +251,7 @@ _nl_remove_locale (int locale, struct lo
if (--data->usage_count == 0)
{
/* First search the entry in the list of loaded files. */
- struct loaded_l10nfile *ptr = locale_file_list[locale];
+ struct loaded_l10nfile *ptr = _nl_locale_file_list[locale];
/* Search for the entry. It must be in the list. Otherwise it
is a bug and we crash badly. */
@@ -287,28 +287,3 @@ _nl_remove_locale (int locale, struct lo
free (data);
}
}
-
-static void __attribute__ ((unused))
-free_mem (void)
-{
- int category;
-
- for (category = 0; category < __LC_LAST; ++category)
- if (category != LC_ALL)
- {
- struct loaded_l10nfile *runp = locale_file_list[category];
-
- while (runp != NULL)
- {
- struct loaded_l10nfile *here = runp;
- struct locale_data *data = (struct locale_data *) runp->data;
-
- if (data != NULL && data != _nl_C[category])
- _nl_unload_locale (data);
- runp = runp->next;
- free ((char *) here->filename);
- free (here);
- }
- }
-}
-text_set_element (__libc_subfreeres, free_mem);
--- locale/setlocale.c.unload Thu Jun 28 12:17:24 2001
+++ locale/setlocale.c Thu Jun 28 13:13:35 2001
@@ -430,6 +430,7 @@ setlocale (int category, const char *loc
}
}
+extern struct loaded_l10nfile *_nl_locale_file_list[];
static void __attribute__ ((unused))
free_mem (void)
@@ -440,17 +441,30 @@ free_mem (void)
if (category != LC_ALL)
{
struct locale_data *here = *_nl_current[category];
+ struct loaded_l10nfile *runp = _nl_locale_file_list[category];
/* If this category is already "C" don't do anything. */
- if (here == _nl_C[category])
- continue;
+ if (here != _nl_C[category])
+ {
+ /* We have to be prepared that sometime later me still
+ might need the locale information. */
+ setdata (category, _nl_C[category]);
+ setname (category, _nl_C_name);
- /* We have to be prepared that sometime later me still might
- need the locale information. */
- setdata (category, _nl_C[category]);
- setname (category, _nl_C_name);
+ _nl_unload_locale (here);
+ }
- _nl_unload_locale (here);
+ while (runp != NULL)
+ {
+ struct loaded_l10nfile *curr = runp;
+ struct locale_data *data = (struct locale_data *) runp->data;
+
+ if (data != NULL && data != here && data != _nl_C[category])
+ _nl_unload_locale (data);
+ runp = runp->next;
+ free ((char *) curr->filename);
+ free (curr);
+ }
}
setname (LC_ALL, _nl_C_name);
More information about the Libc-alpha
mailing list