[sheepdog] [PATCH] util: make xvalloc() return zeroed memory

Liu Yuan namei.unix at gmail.com
Wed Jan 15 08:16:00 CET 2014


This actuall fixes a bug that 045 fails with -ec specified. Instead of add a
memset() to init_erasure_buffer() to fix the bug, I prefer to make xvalloc()
a zeroed memory version, because:

- present CPU and glibc is very good at zero out a memory region.
- zeroed version will avoid future misuage of xvalloc() that expect it to return
  zeroed memory.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 lib/util.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/util.c b/lib/util.c
index 06ff8fd..aa4ffb2 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -93,11 +93,13 @@ void *xcalloc(size_t nmemb, size_t size)
 	return ret;
 }
 
+/* zeroed memory version of valloc() */
 void *xvalloc(size_t size)
 {
 	void *ret = valloc(size);
 	if (unlikely(!ret))
 		panic("Out of memory");
+	memset(ret, 0, size);
 	return ret;
 }
 
-- 
1.8.1.2




More information about the sheepdog mailing list