How to suppress valgrind warnings from gpgme?

387 views Asked by At

I'm trying to use GPGME in my code to verify some signatures. However, simply initializing and releasing the GPGME contexts causes valgrind to spew a large number of warnings.

For example:

#include <gpgme.h>

int main() {
    gpgme_check_version(NULL);
    gpgme_ctx_t my_ctx;
    gpgme_error_t gpg_err;

    gpg_err = gpgme_new(&my_ctx);

    gpgme_release(my_ctx);

    return 0;
}

Compile this with gcc -lgpgme -lassuan -lgpg-error main.c and then run it under valgrind. From valgrind -v ./a.out, it seems like this code starts 6 different processes. I've copied the relevant warning messages:

==19158== Warning: invalid file descriptor 1024 in syscall close()
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1025 in syscall close()
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1026 in syscall close()
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1027 in syscall close()
==19158==    Use --log-fd=<number> to select an alternative log fd.
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1028 in syscall close()
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)
==19158== Warning: invalid file descriptor 1029 in syscall close()
==19158==    at 0x558DBC4: close (in /usr/lib/libc-2.26.so)
==19158==    by 0x4E65DF8: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E66D65: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6736B: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56572: gpgme_get_engine_info (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E56C87: ??? (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x4E6838F: gpgme_new (in /usr/lib/libgpgme.so.11.19.0)
==19158==    by 0x10880B: main (in /home/thedoctor/Programming/gpgmetest/mytest)

The exact same set of warnings is repeated for 6 different processes in total. It seems like GPGME tries to close some file descriptors that is doesn't own.

My question is twofold:

  1. Am I using the gpgme API wrong? Is there something else I need to do?
  2. If the usage of the API is correct, how can I suppress these warnings from valgrind?

I can't seem to get valgrind to produce suppressions for these warnings. Running valgrind --gen-suppressions=all -v ./a.out doesn't show any suppressions in the output. I guess that is because these are warnings and not real errors. I tried writing a suppression myself, but I'm not sure what the type should be. Usually, when I have had to write suppressions, they are for Memcheck:Leak. But what category do these warnings fall into?

EDIT: Here is a suppression I tried writing:

{
    gpgme-leak-fd
    fun:close
    ...
    fun:gpgme_new
}

EDIT 2: I tried to put a bounty, but it expired. If you have a valid answer for this, I offer a bounty of 100 rep.

1

There are 1 answers

1
Teddy On

Here are some rules for GPGME written by Dan McGee, taken from here:

{
   gpgme-static-get-engine-info
   Memcheck:Leak
   fun:malloc
   ...
   fun:gpgme_get_engine_info
}
{
   gpgme-static-set-engine-info
   Memcheck:Leak
   fun:malloc
   ...
   fun:_gpgme_set_engine_info
   fun:gpgme_set_engine_info
}
{
   gpgme-static-set-locale
   Memcheck:Leak
   fun:malloc
   fun:strdup
   fun:gpgme_set_locale
}