Now @mp_drop@ checks its argument is non-NULL before attempting to free
authormdw <mdw>
Sat, 3 Feb 2001 12:00:29 +0000 (12:00 +0000)
committermdw <mdw>
Sat, 3 Feb 2001 12:00:29 +0000 (12:00 +0000)
it.  Note that the macro version @MP_DROP@ doesn't do this.

bbs-rand.c
mp-mem.c
mp-modsqrt.c
mp-sqrt.c
mpmont.c
mpmul.c

index dbca23c..abe1e72 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: bbs-rand.c,v 1.3 2000/06/17 10:45:21 mdw Exp $
+ * $Id: bbs-rand.c,v 1.4 2001/02/03 12:00:29 mdw Exp $
  *
  * Blum-Blum-Shub secure random number generator
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: bbs-rand.c,v $
+ * Revision 1.4  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.3  2000/06/17 10:45:21  mdw
  * Typesetting fixes.  Advertise random number generator strength.  Use
  * secure arena for memory allocation.
@@ -134,8 +138,7 @@ void bbs_step(bbs *b)
 
 void bbs_set(bbs *b, mp *x)
 {
-  if (b->x)
-    mp_drop(b->x);
+  mp_drop(b->x);
   b->x = MP_COPY(x);
   bbs_step(b);
 }
index 7f9d630..f35fd58 100644 (file)
--- a/mp-mem.c
+++ b/mp-mem.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp-mem.c,v 1.3 2000/06/17 11:45:09 mdw Exp $
+ * $Id: mp-mem.c,v 1.4 2001/02/03 12:00:29 mdw Exp $
  *
  * Memory management for multiprecision numbers
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mp-mem.c,v $
+ * Revision 1.4  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.3  2000/06/17 11:45:09  mdw
  * Major memory management overhaul.  Added arena support.  Use the secure
  * arena for secret integers.  Replace and improve the MP management macros
@@ -191,7 +195,7 @@ mp *mp_copy(mp *m) { return MP_COPY(m); }
  *             If there are no more references, the integer is destroyed.
  */
 
-void mp_drop(mp *m) { MP_DROP(m); }
+void mp_drop(mp *m) { if (m) MP_DROP(m); }
 
 /* --- @mp_split@ --- *
  *
index 1c66c78..6c21dc4 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp-modsqrt.c,v 1.2 2000/10/08 12:02:21 mdw Exp $
+ * $Id: mp-modsqrt.c,v 1.3 2001/02/03 12:00:29 mdw Exp $
  *
  * Compute square roots modulo a prime
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mp-modsqrt.c,v $
+ * Revision 1.3  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.2  2000/10/08 12:02:21  mdw
  * Use @MP_EQ@ instead of @MP_CMP@.
  *
@@ -78,8 +82,7 @@ mp *mp_modsqrt(mp *d, mp *a, mp *p)
   /* --- Cope if %$a \not\in Q_p$% --- */
 
   if (mp_jacobi(a, p) != 1) {
-    if (d)
-      mp_drop(d);
+    mp_drop(d);
     return (0);
   }
 
@@ -146,8 +149,7 @@ mp *mp_modsqrt(mp *d, mp *a, mp *p)
   d = mpmont_reduce(&mm, d, r);
   mp_drop(ainv);
   mp_drop(r); mp_drop(c);
-  if (dd)
-    mp_drop(dd);
+  mp_drop(dd);
   mp_drop(mone);
   mpmont_destroy(&mm);
 
@@ -194,8 +196,7 @@ static int verify(dstr *v)
 
   mp_drop(a);
   mp_drop(p);
-  if (r)
-    mp_drop(r);
+  mp_drop(r);
   mp_drop(rr);
   assert(mparena_count(MPARENA_GLOBAL) == 0);
   return (ok);
index 6b0f602..7b65ec0 100644 (file)
--- a/mp-sqrt.c
+++ b/mp-sqrt.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp-sqrt.c,v 1.2 2000/10/08 12:02:21 mdw Exp $
+ * $Id: mp-sqrt.c,v 1.3 2001/02/03 12:00:29 mdw Exp $
  *
  * Compute integer square roots
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mp-sqrt.c,v $
+ * Revision 1.3  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.2  2000/10/08 12:02:21  mdw
  * Use @MP_EQ@ instead of @MP_CMP@.
  *
@@ -71,8 +75,7 @@ mp *mp_sqrt(mp *d, mp *a)
 
   MP_SHRINK(a);
   if (a->v == a->vl) {
-    if (d)
-      mp_drop(d);
+    mp_drop(d);
     return (MP_ZERO);
   }
 
@@ -116,8 +119,7 @@ mp *mp_sqrt(mp *d, mp *a)
   /* --- Finished, at last --- */
 
   mp_drop(q);
-  if (r)
-    mp_drop(r);
+  mp_drop(r);
   return (d);
 }
 
index d000f8d..a6dabe3 100644 (file)
--- a/mpmont.c
+++ b/mpmont.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mpmont.c,v 1.12 2000/10/08 15:48:35 mdw Exp $
+ * $Id: mpmont.c,v 1.13 2001/02/03 12:00:29 mdw Exp $
  *
  * Montgomery reduction
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmont.c,v $
+ * Revision 1.13  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.12  2000/10/08 15:48:35  mdw
  * Rename Karatsuba constants now that we have @gfx_kmul@ too.
  *
@@ -548,10 +552,8 @@ done:
     mp_drop(tab[i]);
   xfree(tab);
 exit:
-  if (d != MP_NEW)
-    mp_drop(d);
-  if (spare)
-    mp_drop(spare);
+  mp_drop(d);
+  mp_drop(spare);
   return (x);
 }
 
diff --git a/mpmul.c b/mpmul.c
index 4541aea..4dd6a68 100644 (file)
--- a/mpmul.c
+++ b/mpmul.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mpmul.c,v 1.3 2000/10/08 12:11:22 mdw Exp $
+ * $Id: mpmul.c,v 1.4 2001/02/03 12:00:29 mdw Exp $
  *
  * Multiply many small numbers together
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpmul.c,v $
+ * Revision 1.4  2001/02/03 12:00:29  mdw
+ * Now @mp_drop@ checks its argument is non-NULL before attempting to free
+ * it.  Note that the macro version @MP_DROP@ doesn't do this.
+ *
  * Revision 1.3  2000/10/08 12:11:22  mdw
  * Use @MP_EQ@ instead of @MP_CMP@.
  *
@@ -148,8 +152,7 @@ mp *mp_factorial(unsigned long i)
     x = mp_fromulong(x, j);
     mpmul_add(&b, x);
   }
-  if (x)
-    mp_drop(x);
+  mp_drop(x);
   return (mpmul_done(&b));
 }