Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

valgrind complains about uninitialized memory #14

Open
romanbsd opened this issue Jun 10, 2018 · 1 comment
Open

valgrind complains about uninitialized memory #14

romanbsd opened this issue Jun 10, 2018 · 1 comment

Comments

@romanbsd
Copy link

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.

@antirez
Copy link
Owner

antirez commented Jul 18, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants