valgrindcalloc

valgrind thinks calloc allocated memory is ununitialized


From the linux manual page on calloc, we learn that:

"The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero."

When it is set to zero, it means it is initialized.

Yet, valgrind will report this...

Syscall param writev(vector[...]) points to uninitialised byte(s)
...
Address 0x28805be0 is 32 bytes inside a block of size 16,384 alloc'd
  at 0x4849A83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)

...on memory that was allocated as calloc(1,16384)

How can calloc-allocated memory ever be considered as uninitialized by Valgrind?

OS: Ubuntu 22.10

Kernel: 5.19.0

Valgrind: 3.18.1

UPDATE: I tried valgrind 3.20 as well: same behaviour.


Solution

  • This happens because after the initial clearing with zeros, it is overwritten with other data that was uninitialized.

    To see what other data got put in there, you can use the valgrind flag --track-origins=yes