unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Fix double-free error on non-GNU systems.
@ 2012-01-28  6:42 Chris K. Jester-Young
  2012-01-28 20:05 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Chris K. Jester-Young @ 2012-01-28  6:42 UTC (permalink / raw)
  To: guile-devel

* libguile/i18n.c (scm_make_locale): Null out c_locale_name after it's
  freed, so it doesn't get freed again. While this only has effect if
  USE_GNU_LOCALE_API is unset, the nulling out happens in both cases,
  to be consistent and robust.
  (scm_nl_langinfo): Free c_result in all switch cases, in particular
  P_SIGN_POSN, N_SIGN_POSN, INT_P_SIGN_POSN, and INT_N_SIGN_POSN.
---
 libguile/i18n.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/libguile/i18n.c b/libguile/i18n.c
index 4bb9e21..5a53bfa 100644
--- a/libguile/i18n.c
+++ b/libguile/i18n.c
@@ -645,6 +645,7 @@ SCM_DEFINE (scm_make_locale, "make-locale", 2, 1, 0,
   c_locale = newlocale (c_category_mask, c_locale_name, c_base_locale);
 
   free (c_locale_name);
+  c_locale_name = NULL;
 
   if (c_locale == (locale_t) 0)
     {
@@ -662,6 +663,7 @@ SCM_DEFINE (scm_make_locale, "make-locale", 2, 1, 0,
   c_locale->category_mask = c_category_mask;
   c_locale->locale_name = scm_gc_strdup (c_locale_name, "locale");
   free (c_locale_name);
+  c_locale_name = NULL;
 
   if (scm_is_eq (base_locale, SCM_VARIABLE_REF (scm_global_locale)))
     {
@@ -1652,6 +1654,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
 	    default:
 	      result = scm_from_latin1_symbol ("unspecified");
 	    }
+	  free (c_result);
 	  break;
 #endif
 
-- 
1.7.2.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix double-free error on non-GNU systems.
  2012-01-28  6:42 [PATCH] Fix double-free error on non-GNU systems Chris K. Jester-Young
@ 2012-01-28 20:05 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2012-01-28 20:05 UTC (permalink / raw)
  To: guile-devel

Hello!

"Chris K. Jester-Young" <cky944@gmail.com> skribis:

> * libguile/i18n.c (scm_make_locale): Null out c_locale_name after it's
>   freed, so it doesn't get freed again. While this only has effect if
>   USE_GNU_LOCALE_API is unset, the nulling out happens in both cases,
>   to be consistent and robust.

How do you reproduce the system?  I tried (make-locale LC_ALL "sdf") on
FreeBSD, and I don’t see any problems (it could be that the double-free
is silently ignored, though.)

If you find a case that reproducibly leads to a crash, it would be nice
to add it to i18n.test.

>   (scm_nl_langinfo): Free c_result in all switch cases, in particular
>   P_SIGN_POSN, N_SIGN_POSN, INT_P_SIGN_POSN, and INT_N_SIGN_POSN.

Indeed.

Thanks for catching those, and feel free to commit!

Ludo’.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-28 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-28  6:42 [PATCH] Fix double-free error on non-GNU systems Chris K. Jester-Young
2012-01-28 20:05 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).