Based on a patch by Eli Zaretskii <eliz@gnu.org>.
* libguile/i18n.c (copy_string_or_null): New static function.
(scm_nl_langinfo): Use 'copy_string_or_null' to copy the result from
'nl_langinfo' and 'nl_langinfo_l' before the next call and before
releasing the locale mutex.
-/* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+/* Copyright (C) 2006-2014 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
Note: We don't use Gnulib's `nl_langinfo' module because it's currently not
as complete as the compatibility hacks in `i18n.scm'. */
Note: We don't use Gnulib's `nl_langinfo' module because it's currently not
as complete as the compatibility hacks in `i18n.scm'. */
+static char *
+copy_string_or_null (const char *s)
+{
+ if (s == NULL)
+ return NULL;
+ else
+ return strdup (s);
+}
SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
(SCM item, SCM locale),
SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
(SCM item, SCM locale),
if (c_locale != NULL)
{
#ifdef USE_GNU_LOCALE_API
if (c_locale != NULL)
{
#ifdef USE_GNU_LOCALE_API
- c_result = nl_langinfo_l (c_item, c_locale);
- codeset = nl_langinfo_l (CODESET, c_locale);
+ c_result = copy_string_or_null (nl_langinfo_l (c_item, c_locale));
+ codeset = copy_string_or_null (nl_langinfo_l (CODESET, c_locale));
#else /* !USE_GNU_LOCALE_API */
/* We can't use `RUN_IN_LOCALE_SECTION ()' here because the locale
mutex is already taken. */
#else /* !USE_GNU_LOCALE_API */
/* We can't use `RUN_IN_LOCALE_SECTION ()' here because the locale
mutex is already taken. */
scm_locale_error (FUNC_NAME, lsec_err);
else
{
scm_locale_error (FUNC_NAME, lsec_err);
else
{
- c_result = nl_langinfo (c_item);
- codeset = nl_langinfo (CODESET);
+ c_result = copy_string_or_null (nl_langinfo (c_item));
+ codeset = copy_string_or_null (nl_langinfo (CODESET));
restore_locale_settings (&lsec_prev_locale);
free_locale_settings (&lsec_prev_locale);
restore_locale_settings (&lsec_prev_locale);
free_locale_settings (&lsec_prev_locale);
- c_result = nl_langinfo (c_item);
- codeset = nl_langinfo (CODESET);
+ c_result = copy_string_or_null (nl_langinfo (c_item));
+ codeset = copy_string_or_null (nl_langinfo (CODESET));
- if (c_result != NULL)
- c_result = strdup (c_result);
-
unlock_locale_mutex ();
if (c_result == NULL)
unlock_locale_mutex ();
if (c_result == NULL)
+ if (codeset != NULL)
+ free (codeset);
+
return result;
}
#undef FUNC_NAME
return result;
}
#undef FUNC_NAME