[AC] Fix bignum/bigfloat memory leaks

Jerry James <[email protected]> Tue, 23 Sep 2014 16:49:16 -0600
Newsgroups gmane.emacs.xemacs.patches
Message-ID <CAHCOHQmYDTHSUhVSRmyGpoeUAX3kS6Ua14p6FcNzzDm0i3GaRQ@mail.gmail.com>
APPROVE COMMIT

I'm committing this without waiting under the "obviously correct"
doctrine.  We were creating bignums and bigfloats on the stack, then
not releasing memory properly before they went out of scope.  (We were
calling mpz_init() without a corresponding mpz_clear(), and likewise
for mpf_init() and mpf_clear(), for those familiar with the GMP
interface.)

diff -r 2f22818d92d4 src/ChangeLog
--- a/src/ChangeLog Sat Sep 06 14:30:15 2014 +0100
+++ b/src/ChangeLog Tue Sep 23 16:44:06 2014 -0600
@@ -1,3 +1,8 @@
+2014-09-23  Jerry James  <[email protected]>
+
+ * floatfns.c (round_two_bignum_1): Fix memory leak.
+ (round_two_bigfloat): Ditto.
+
 2014-09-06  Aidan Kehoe  <[email protected]>

  * select-x.c (Fx_store_cutbuffer_internal):
diff -r 2f22818d92d4 src/floatfns.c
--- a/src/floatfns.c Sat Sep 06 14:30:15 2014 +0100
+++ b/src/floatfns.c Tue Sep 23 16:44:06 2014 -0600
@@ -1681,6 +1681,10 @@
       *res = make_bignum_bg (floored);
       *remain = make_bignum_bg (scratch_bignum);
     }
+  bignum_fini (flsecond);
+  bignum_fini (floored);
+  bignum_fini (flooring);
+  bignum_fini (hi2);
 }

 static Lisp_Object
@@ -1835,6 +1839,7 @@
   bigfloat_div (divided, XBIGFLOAT_DATA (number), XBIGFLOAT_DATA (divisor));

   res0 = round_one_bigfloat_1 (divided);
+  bigfloat_fini (divided);

   bigfloat_set_prec (scratch_bigfloat, prec);
   bigfloat_set_prec (scratch_bigfloat2, prec);

-- 
Jerry James
http://www.jamezone.org/