[Ecm-commits] r2436 - branches/6.4.4

cvs commits ecm-commits at lists.gforge.inria.fr
Tue Feb 26 19:46:56 CET 2013


Author: kruppa
Date: 2013-02-26 19:46:56 +0100 (Tue, 26 Feb 2013)
New Revision: 2436

Log:
Replaced several alloca() by malloc() to avoid segfault with very large P+-1 stage 2


Modified:
   branches/6.4.4/mul_fft.c
Modified: branches/6.4.4/mul_fft.c
===================================================================
--- branches/6.4.4/mul_fft.c	2013-02-26 18:44:05 UTC (rev 2435)
+++ branches/6.4.4/mul_fft.c	2013-02-26 18:46:56 UTC (rev 2436)
@@ -1616,7 +1616,7 @@
   BufA = TMP_ALLOC_MP_PTRS (K1);
   ASSERT(BufA != NULL);
 
-  T = TMP_ALLOC_LIMBS(nprime + 1);
+  T = __GMP_ALLOCATE_FUNC_LIMBS(nprime + 1);
   ASSERT(T != NULL);
 
   if (nl > Kl)
@@ -1650,6 +1650,8 @@
     tmp = NULL;
     n = NULL; /* n is now likewise invalid */
   }
+  __GMP_FREE_FUNC_LIMBS (T, nprime + 1);
+  T = NULL;
 
   omegai = omega<<k1;
   for (j = 0; j < K1; ++j)
@@ -1832,7 +1834,7 @@
       ASSERT(Ap != NULL);
       Bp = TMP_ALLOC_MP_PTRS (K2);
       ASSERT(Bp != NULL);
-      A = TMP_ALLOC_LIMBS (2 * K2 * (nprime2 + 1));
+      A = __GMP_ALLOCATE_FUNC_LIMBS (2 * K2 * (nprime2 + 1));
       ASSERT(A != NULL);
       T = TMP_ALLOC_LIMBS (2 * (nprime2 + 1));
       ASSERT(T != NULL);
@@ -1917,6 +1919,8 @@
 	  }
 	}
       }
+      __GMP_FREE_FUNC_LIMBS (A, 2 * K2 * (nprime2 + 1));
+      A = NULL;
     }
   else
     {
@@ -2139,12 +2143,11 @@
 				    some Ap[i] may point to the B[] array,
 				    and will be erase since we use the B[]
 				    array to store the final result {p,pla} */
-  TMP_DECL;
-  TMP_MARK;
+  mp_ptr bufAptr, bufBptr; /* Remember pointers to free memory */
 
-  rotbufA[0] = TMP_ALLOC_LIMBS(nprime+1);
+  bufAptr = rotbufA[0] = __GMP_ALLOCATE_FUNC_LIMBS(nprime+1);
   ASSERT(rotbufA[0] != NULL);
-  rotbufB[0] = TMP_ALLOC_LIMBS(nprime+1);
+  bufBptr = rotbufB[0] = __GMP_ALLOCATE_FUNC_LIMBS(nprime+1);
   ASSERT(rotbufB[0] != NULL);
 
   ASSERT(b == 1 || b == -1);
@@ -2271,7 +2274,8 @@
   if (rec) /* store the carry out */
     op[pl] = i;
 
-  TMP_FREE;
+  __GMP_FREE_FUNC_LIMBS(bufAptr, nprime+1);
+  __GMP_FREE_FUNC_LIMBS(bufBptr, nprime+1);
 
   return i;
 }
@@ -2421,7 +2425,7 @@
     }
   ASSERT_ALWAYS (nprime < pl); /* otherwise we'll loop */
 
-  T = TMP_ALLOC_LIMBS (2 * (nprime + 1));
+  T = __GMP_ALLOCATE_FUNC_LIMBS (2 * (nprime + 1));
   ASSERT(T != NULL);
 
   TRACE (printf ("mpn_mul_fft_aux: %dx%d limbs -> %d times %dx%d limbs (%1.2f)\n",
@@ -2444,6 +2448,7 @@
                             l, _fft_l, T, 0, b);
 
   TMP_FREE;
+  __GMP_FREE_FUNC_LIMBS (T, 2 * (nprime + 1));
   __GMP_FREE_FUNC_LIMBS (A, 2 * K * (nprime + 1));
   if (use_tmp_n)
     __GMP_FREE_FUNC_LIMBS ((mp_ptr) n, pl + (b == 1));




More information about the Ecm-commits mailing list