r27206 - trunk/contrib/fec/src/csrc

[email protected] Wed, 22 Apr 2009 09:10:31 +0000
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: j16sdiz
Date: 2009-04-22 09:10:31 +0000 (Wed, 22 Apr 2009)
New Revision: 27206

Modified:
   trunk/contrib/fec/src/csrc/fec.c
Log:
Don't free immediatly, or we will get the same addr

Modified: trunk/contrib/fec/src/csrc/fec.c
===================================================================
--- trunk/contrib/fec/src/csrc/fec.c	2009-04-22 08:46:42 UTC (rev 27205)
+++ trunk/contrib/fec/src/csrc/fec.c	2009-04-22 09:10:31 UTC (rev 27206)
@@ -617,17 +617,25 @@
 }
 
 // HACK: allocate a memory in low 32 bit region
+#define MALLOC_LOW_TRY 32
 static void *
 my_malloc_low(int sz, char *err_string)
 {
-	int i;
-	for (i = 0 ; i < 30 ; i++) {
-		void *p = my_malloc(sz, err_string);
-		if (((uint32_t)(uintptr_t)p) == (uintptr_t)p)
-			return p;
-		
-		free(p);
+	void* p[MALLOC_LOW_TRY];
+	int i, j;
+
+	for (i = 0 ; i < MALLOC_LOW_TRY ; i++) {
+		p[i] = my_malloc(sz, err_string);
+		if (((uint32_t)(uintptr_t)p[i]) == (uintptr_t)p[i]) {
+			for (j = 0; j < i; j++)
+				free(p[j]);
+			return p[i];
+		}
 	}
+
+	for (j = 0; j < i; j++)
+		free(p[j]);
+
 	fprintf(stderr, "-- malloc failure allocating low %s\n", err_string);
 	exit(1) ;
 }