Browse Source

malloc-simple: Make calloc() return zeroed memory

The 0.9.31 release included a change to malloc-simple to request
uninitialized memory from noMMU kernels. Unfortunately, the corresponding
calloc() code assumed that memory returned by malloc() was already zeroed,
which leads to all kinds of nastiness.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Steven J. Magnani 15 years ago
parent
commit
8a08aeeaa0
1 changed files with 4 additions and 5 deletions
  1. 4 5
      libc/stdlib/malloc-simple/alloc.c

+ 4 - 5
libc/stdlib/malloc-simple/alloc.c

@@ -60,11 +60,10 @@ void * calloc(size_t nmemb, size_t lsize)
 		__set_errno(ENOMEM);
 		return NULL;
 	}
-	result=malloc(size);
-#if 0
-	/* Standard unix mmap using /dev/zero clears memory so calloc
-	 * doesn't need to actually zero anything....
-	 */
+	result = malloc(size);
+
+#ifndef __ARCH_USE_MMU__
+	/* mmap'd with MAP_UNINITIALIZE, we have to blank memory ourselves */
 	if (result != NULL) {
 		memset(result, 0, size);
 	}