fix `free' of mpz_to_str
authorAndy Wingo <wingo@pobox.com>
Fri, 2 Dec 2011 18:18:05 +0000 (19:18 +0100)
committerAndy Wingo <wingo@pobox.com>
Fri, 2 Dec 2011 18:18:05 +0000 (19:18 +0100)
* libguile/numbers.c (scm_number_to_string): Don't `free' the result of
  mpz_get_str; use the mp free function.

libguile/numbers.c

index e5b4ed9..6938381 100644 (file)
@@ -5330,8 +5330,14 @@ SCM_DEFINE (scm_number_to_string, "number->string", 1, 1, 0,
   else if (SCM_BIGP (n))
     {
       char *str = mpz_get_str (NULL, base, SCM_I_BIG_MPZ (n));
+      size_t len = strlen (str);
+      void (*freefunc) (void *, size_t);
+      SCM ret;
+      mp_get_memory_functions (NULL, NULL, &freefunc);
       scm_remember_upto_here_1 (n);
-      return scm_take_locale_string (str);
+      ret = scm_from_latin1_stringn (str, len);
+      freefunc (str, len + 1);
+      return ret;
     }
   else if (SCM_FRACTIONP (n))
     {