Page MenuHome GnuPG

Memory leak (heisenbug) within gpgme_op_keylist_start()
Closed, ResolvedPublic

Description

I have a strange (but very real problem). When I call gpgme_op_keylist_start()
or gpgme_get_key() gpgme seems to leak memory (according to valgrind). The
weird part is that when I redirect stdout and stderr to a file (from valgrind)
the leak is no longer reported. I am attaching a simple program that
illustrates the bug (hoping this is user error on my part). To compile it:

g++ simple-signer.cc -o simple-signer -lgpgme-pthread

Valgrind is VERY verbose, but the part the is worrisome here is:
...

4104== 14 bytes in 2 blocks are definitely lost in loss record 1 of 5

4104== at 0x4C22FAB: malloc (vg_replace_malloc.c:207)

4104== by 0x5864DD1: strdup (in /lib/libc-2.7.so)

4104== by 0x4E2DE25: (within /usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x4E3A66E: (within /usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x4E37206: (within /usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x4E3033A: (within /usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x4E33FF4: gpgme_op_keylist_start (in

/usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x4E342F6: gpgme_get_key (in /usr/lib/libgpgme-pthread.so.11.6.4)

4104== by 0x401986: main (in /home/eoster/giveup/simple-signer)

...

4104== LEAK SUMMARY:

4104== definitely lost: 14 bytes in 2 blocks.

4104== possibly lost: 0 bytes in 0 blocks.

4104== still reachable: 422 bytes in 11 blocks.

4104== suppressed: 0 bytes in 0 blocks.

I have a version of this program that runs in a loop and the number of bytes
lost seems to increase as I repeat these operations.

Details

Version
1.1.5

Event Timeline

Platform info:
Linux <machine> 2.6.24-21-server #1 SMP Tue Oct 21 23:40:13 UTC 2008 x86_64
GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 8.04.2
Release: 8.04
Codename: hardy

Please check the version. Do you mean 1.1.6 with Ubuntu patch 4?

I can not reproduce this. Can you please run this with a gpgme library with
debug symbols so we get a full backtrace out of valgrind?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mar 20, 2009, at 5:16 AM, Werner Koch via BTS wrote:

Werner Koch <wk@gnupg.org> added the comment:

Please check the version. Do you mean 1.1.6 with Ubuntu patch 4?

So, I just printed the output from the get engine routines and this is
what I have:
Initialized with GPGME version "1.1.5", protocol "OpenPGP", file: "/
usr/bin/gpg", home: "(null)"
Apparently the libraries that are named 1.1.6 are not correct?

At any rate, I would assume this is w/ the Ubuntu patch since it came
from apt-get. Is there some other way you would like me to check?

Eric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)

iEYEARECAAYFAknDqb0ACgkQK/tq6CJjZQLSCgCeI9MYLKHgJkzalcSZvYUDlycd
ZWMAn2H83MuDS9mmNy/7B9SF5U1Dx+GM

n9HW

-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mar 20, 2009, at 6:00 AM, Marcus Brinkmann via BTS wrote:

Marcus Brinkmann <marcus@g10code.com> added the comment:

I can not reproduce this. Can you please run this with a gpgme
library with
debug symbols so we get a full backtrace out of valgrind?

Sure, but when I try to download the source my connection hangs (has
been doing this all night). Can you send me a link to get the source?

Eric

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)

iEYEARECAAYFAknDqeYACgkQK/tq6CJjZQJFcQCgnWzXX366OH6Ghepc7choBqJC
e1kAn1duzUXtPcw0JASeQc9o/rdhGrcd

ioOH

-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mar 20, 2009, at 6:00 AM, Marcus Brinkmann via BTS wrote:

Marcus Brinkmann <marcus@g10code.com> added the comment:

I can not reproduce this. Can you please run this with a gpgme
library with
debug symbols so we get a full backtrace out of valgrind?

Sorry about my last, here is a stack taken from a build of 1.1.5:

10983== 12 bytes in 2 blocks are definitely lost in loss record 1 of 5

10983== at 0x4C22FAB: malloc (vg_replace_malloc.c:207)

10983== by 0x5858DD1: strdup (in /lib/libc-2.7.so)

10983== by 0x4E2CBD5: _gpgme_getenv (get-env.c:47)

10983== by 0x4E393EE: gpg_new (rungpg.c:491)

10983== by 0x4E35F86: _gpgme_engine_new (engine.c:407)

10983== by 0x4E2F0EA: _gpgme_op_reset (op-support.c:98)

10983== by 0x4E32D94: gpgme_op_keylist_start (keylist.c:813)

10983== by 0x4E33096: gpgme_get_key (keylist.c:960)

10983== by 0x401986: main (in /home/eoster/giveup/simple-signer)

This does not include any Ubunto patches, it was taken from the
original source for 1.1.5.

Eric
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)

iEYEARECAAYFAknDsfQACgkQK/tq6CJjZQISJwCgmO0Bx1X4fik5OcfbyukFnJ5J
2X8AoJpFyXX820K1ovTrFi5PQJTi/fr3

JlIn

-----END PGP SIGNATURE-----

Ok, I can understand that now if you use GPGME 1.1.5. This was fixed a long
time ago:

2007-09-13 Marcus Brinkmann <marcus@g10code.de>

  • rungpg.c (gpg_new): Handle return value of _gpgme_getenv (fixes small memory leak).

It's fixed since version 1.1.6, but not in 1.1.5.

I'm closing the report, you can reopen it if updating to a newer GPGME version
doesn't fix it.

Thanks,
Marcus

marcus lowered the priority of this task from Unbreak Now! to Normal.
marcus changed Version from 11.6.4 to 1.1.5.