I've got a gcc 4.9.1 program using boost::asio (1.61), which valgrind 3.12.0 reports occasional errors on. I'm having a hard time understanding exactly what I'm looking at and hoping someone can help.
Valgrind traps this error:
==154023== Syscall param sendmsg(msg.msg_iov[0]) points to uninitialised byte(s)
==154023== at 0x8FB3C6D: ??? (in /usr/lib64/libpthread-2.17.so)
==154023== by 0x4F47287: boost::asio::detail::socket_ops::send(int, iovec const*, unsigned long, int, boost::system::error_code&) (socket_ops.ipp:1170)
/* many levels elided */
==154023== Address 0xe01cea4 is 9,396 bytes inside a block of size 524,304 alloc'd
==154023== at 0x4C2AAFB: operator new[](unsigned long, std::nothrow_t const&) (vg_replace_malloc.c:466)
In the attached debugger, I look at the call into sendmsg
:
(gdb) print msg
$1 = {
msg_name = 0x0,
msg_namelen = 0,
msg_iov = 0x101c93c0,
msg_iovlen = 2,
msg_control = 0x0,
msg_controllen = 0,
msg_flags = 0
}
(gdb) print msg.msg_iov[0]
$2 = {
iov_base = 0xe01cdf0,
iov_len = 198
}
(gdb) print &msg.msg_iov[0]
$3 = (iovec *) 0x101c93c0
If I am reading valgrind's complaint right, it thinks the memory at 0xe01cea4 is uninitialized. But it is. If I examine the 198 bytes of memory starting at 0xe01cdf0, I see my outgoing message exactly as expected. 0xe01cea4 is 180 bytes into that region, and has most definitely been initialized. Either I'm misunderstanding what valgrind is telling me, or this is a false positive. I'm inclined to believe it's my fault.
Furthermore, I'm wondering why valgrind is interested in that 0xe01cea4 address anyway. I can't find any other data structure using that value. This makes me think it's valgrind.
But lastly, this code cycles through many times, but only complains occasionally, which leads me back toward thinking there is something strange going on in my code after all.
Any light anyone can shed on what valgrind is telling me here would be appreciated.