1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

fix leak in get_current_locale()

* libguile/i18n.c (get_current_locale): Hold the locale name in a
  GC-managed string, not a mallocated string.  Thanks to Stefan
  Israelsson Tampe for the report.
This commit is contained in:
Andy Wingo 2011-08-16 13:16:21 +02:00
parent e7a81c7acd
commit 42f9581238

View file

@ -501,7 +501,6 @@ get_current_locale (SCM *result)
c_locale = scm_gc_malloc (sizeof (* c_locale), "locale"); c_locale = scm_gc_malloc (sizeof (* c_locale), "locale");
lock_locale_mutex (); lock_locale_mutex ();
c_locale->category_mask = LC_ALL_MASK; c_locale->category_mask = LC_ALL_MASK;
@ -509,20 +508,16 @@ get_current_locale (SCM *result)
current_locale = setlocale (LC_ALL, NULL); current_locale = setlocale (LC_ALL, NULL);
if (current_locale != NULL) if (current_locale != NULL)
{ c_locale->locale_name = scm_gc_strdup (current_locale);
c_locale->locale_name = strdup (current_locale);
if (c_locale->locale_name == NULL)
err = ENOMEM;
}
else else
err = EINVAL; err = EINVAL;
unlock_locale_mutex (); unlock_locale_mutex ();
if (err) if (err == 0)
scm_gc_free (c_locale, sizeof (* c_locale), "locale");
else
SCM_NEWSMOB (*result, scm_tc16_locale_smob_type, c_locale); SCM_NEWSMOB (*result, scm_tc16_locale_smob_type, c_locale);
else
*result = SCM_BOOL_F;
return err; return err;
} }