Search code examples
c++memory-leaksvalgrind

Make a valgrind error suppression generic for a system call


Using valgrind in the context of a C++ project, I have been trying to suppress uninitialised byte information coming from system calls within third party libraries. How could I generate the specific suppression for the following similar warnings?

Syscall param sendmsg(msg.msg_iov[12]) points to uninitialised byte(s) 
==9473==    at 0x740E6F7: sendmsg (sendmsg.c:28) 
==9473==    by 0xA2AB34A: tcp_send(int, msghdr const*, int) (in /usr/local/lib/libgrpc.so.15.0.0) 
==9473==    by 0xA2ACB6C: tcp_flush((anonymous namespace)::grpc_tcp*, grpc_error**) (in /usr/local/lib/libgrpc.so.15.0.0) 
Syscall param sendmsg(msg.msg_iov) points to uninitialised byte(s) 
==9473==    at 0x740E6F7: sendmsg (sendmsg.c:28) 
==9473==    by 0xA2AB34A: tcp_send(int, msghdr const*, int) (in /usr/local/lib/libgrpc.so.15.0.0) 
==9473==    by 0xA2ACB6C: tcp_flush((anonymous namespace)::grpc_tcp*, grpc_error**) (in /usr/local/lib/libgrpc.so.15.0.0) 
Syscall param sendmsg(msg.msg_iov[2]) points to uninitialised byte(s) 
==9473==    at 0x740E6F7: sendmsg (sendmsg.c:28) 
==9473==    by 0xA2AB34A: tcp_send(int, msghdr const*, int) (in /usr/local/lib/libgrpc.so.15.0.0) 
==9473==    by 0xA2ACB6C: tcp_flush((anonymous namespace)::grpc_tcp*, grpc_error**) (in /usr/local/lib/libgrpc.so.15.0.0) 

I've tried both

{
   sendmsg_uninitialized_bytes
   Memcheck:Param
   sendmsg(msg.msg_iov)
   fun:sendmsg
}

and

{
   sendmsg_uninitialized_bytes
   Memcheck:Param
   sendmsg(msg.msg_iov*)
   fun:sendmsg
}

However, None of them works.


Solution

  • Unfortunately this is something of a Valgrind misfeature.

    On the one hand it is more useful for the error message to say which vector element is uninitialized. On the other, since that part of the suppression doesn't support wildcards, it makes writing suppressions more difficult.

    You can slightly ease the suppression writing burden by running with --gen-suppressions=all. You would then need all of the unique suppressions in your suppression file.

    Whilst I see that this is a bit of a pain for users it's also difficult for us to change and keep backwards compatibility.