rax icon indicating copy to clipboard operation
rax copied to clipboard

valgrind complains about uninitialized memory

Open romanbsd opened this issue 7 years ago • 1 comments

The nodes are allocated with malloc and often not initialized. I'm not sure that it's a real problem, but perhaps it's better to use calloc instead of malloc.

diff --git a/app/jni/rax_malloc.h b/app/jni/rax_malloc.h
index e9d5d5d7b..2ebe00665 100755
--- a/app/jni/rax_malloc.h
+++ b/app/jni/rax_malloc.h
@@ -37,7 +37,7 @@
 
 #ifndef RAX_ALLOC_H
 #define RAX_ALLOC_H
-#define rax_malloc malloc
+#define rax_malloc(s) calloc(1, s)
 #define rax_realloc realloc
 #define rax_free free
 #endif

If you want I can create a PR.

romanbsd avatar Jun 10 '18 07:06 romanbsd

Hello @romanbsd, I'll check what are the reports that valgrind outputs. I used valgrind less than normally with Rax because it is not able to deal with pointers stored at unaligned addresses so outputs a ton of false positives. Btw I don't think it's a good idea to fix the problem by replacing malloc with calloc, since many places don't need explicit initialization, so why pay the CPU cost to zero the bytes? Thanks!

antirez avatar Jul 18 '18 16:07 antirez