Debian Bug report logs - #700899
valgrind: still-reachable calloc from dlopen when linked against -lpthread (suppression needed?)

version graph

Package: valgrind; Maintainer for valgrind is Alessandro Ghedini <ghedo@debian.org>; Source for valgrind is src:valgrind (PTS, buildd, popcon).

Affects: libgnutls28, p11-kit

Reported by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>

Date: Mon, 18 Feb 2013 22:33:02 UTC

Severity: normal

Found in version valgrind/1:3.8.1-1

Fixed in version valgrind/1:3.8.1-2

Done: Alessandro Ghedini <ghedo@debian.org>

Bug is archived. No further changes may be made.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, dkg@fifthhorseman.net, Alessandro Ghedini <ghedo@debian.org>:
Bug#700899; Package valgrind. (Mon, 18 Feb 2013 22:33:05 GMT) (full text, mbox, link).


Acknowledgement sent to Daniel Kahn Gillmor <dkg@fifthhorseman.net>:
New Bug report received and forwarded. Copy sent to dkg@fifthhorseman.net, Alessandro Ghedini <ghedo@debian.org>. (Mon, 18 Feb 2013 22:33:05 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: valgrind: still-reachable calloc from dlopen when linked against -lpthread (suppression needed?)
Date: Mon, 18 Feb 2013 17:30:54 -0500
Package: valgrind
Version: 1:3.8.1-1
Severity: normal
Tags: patch

If i link the simple program below with -lpthread, then valgrind
reports a block of 32 bytes still-reachable from calloc within
dlopen().

If i do not link with -lpthread, then valgrind reports no errors.

0 dkg@alice:~$ cat dlopentest.c
#include <dlfcn.h>
#include <stdio.h>

int main() {
  void* x;
  int j;
  x = dlopen("/usr/lib/x86_64-linux-gnu/libm.so", RTLD_LOCAL | RTLD_NOW);
  j = dlclose(x);
  printf("result: %d\n", j);
  printf("bar: %s\n", dlerror());
  return 0;
}
0 dkg@alice:~$ gcc -g -Wall -Werror --pedantic --std=c99 -o dlopentest -ldl -lpthread dlopentest.c
0 dkg@alice:~$ valgrind  --leak-check=full  --show-reachable=yes -- ./dlopentest
==10368== Memcheck, a memory error detector
==10368== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==10368== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==10368== Command: ./dlopentest
==10368== 
result: 0
bar: (null)
==10368== 
==10368== HEAP SUMMARY:
==10368==     in use at exit: 32 bytes in 1 blocks
==10368==   total heap usage: 6 allocs, 5 frees, 1,494 bytes allocated
==10368== 
==10368== 32 bytes in 1 blocks are still reachable in loss record 1 of 1
==10368==    at 0x4C280A4: calloc (vg_replace_malloc.c:593)
==10368==    by 0x4E3235F: _dlerror_run (dlerror.c:142)
==10368==    by 0x4E31EE0: dlopen@@GLIBC_2.2.5 (dlopen.c:88)
==10368==    by 0x400672: main (dlopentest.c:7)
==10368== 
==10368== LEAK SUMMARY:
==10368==    definitely lost: 0 bytes in 0 blocks
==10368==    indirectly lost: 0 bytes in 0 blocks
==10368==      possibly lost: 0 bytes in 0 blocks
==10368==    still reachable: 32 bytes in 1 blocks
==10368==         suppressed: 0 bytes in 0 blocks
==10368== 
==10368== For counts of detected and suppressed errors, rerun with: -v
==10368== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 7)
0 dkg@alice:~$ 

I discovered this while investigating what looked like leaks in
p11-kit, and Stef Walter suggested that the right approach here is
probably just to ask for a valgrind suppression for this particular
leak.

http://lists.freedesktop.org/archives/p11-glue/2013-February/000263.html

I've tested by adding a suppression like the following, and it does
seem to suppress this particular warning:

--- a/usr/lib/valgrind/debian-libc6-dbg.supp	2012-09-19 13:59:48.000000000 -0400
+++ b/usr/lib/valgrind/debian-libc6-dbg.supp	2013-02-18 17:26:16.162482140 -0500
@@ -34,3 +34,11 @@
    fun:__pthread_initialize_manager
    fun:pthread_create@@GLIBC_2.1
 }
+{
+   Debian libpthread (libc6-dbg) - dlopen
+   Memcheck:Leak
+   fun:calloc
+   fun:_dlerror_run
+   fun:dlopen@@GLIBC_2.2.5
+   fun:main
+}

If you decide that this is actually a problem with libc6 instead, feel
free to forward this bug report to that package, and i'll try to help
other people replicate the problem if that's useful.

Thanks for maintaining valgrind in debian!

      --dkg

-- System Information:
Debian Release: 7.0
  APT prefers testing
  APT policy: (500, 'testing'), (200, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 3.7-trunk-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages valgrind depends on:
ii  libc6      2.13-38
ii  libc6-dbg  2.13-38

Versions of packages valgrind recommends:
ii  gdb           7.4.1+dfsg-0.1
ii  valgrind-dbg  1:3.8.1-1

Versions of packages valgrind suggests:
pn  alleyoop      <none>
pn  kcachegrind   <none>
pn  valgrind-mpi  <none>
pn  valkyrie      <none>

-- no debconf information



Information forwarded to debian-bugs-dist@lists.debian.org:
Bug#700899; Package valgrind. (Wed, 20 Feb 2013 10:30:05 GMT) (full text, mbox, link).


Acknowledgement sent to Alessandro Ghedini <ghedo@debian.org>:
Extra info received and forwarded to list. (Wed, 20 Feb 2013 10:30:05 GMT) (full text, mbox, link).


Message #10 received at 700899@bugs.debian.org (full text, mbox, reply):

From: Alessandro Ghedini <ghedo@debian.org>
To: Daniel Kahn Gillmor <dkg@fifthhorseman.net>, 700899@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: Bug#700899: valgrind: still-reachable calloc from dlopen when linked against -lpthread (suppression needed?)
Date: Wed, 20 Feb 2013 11:20:38 +0100
[Message part 1 (text/plain, inline)]
tags 700899 + pending - patch
kthxbye

On lun, feb 18, 2013 at 05:30:54 -0500, Daniel Kahn Gillmor wrote:
> Package: valgrind
> Version: 1:3.8.1-1
> Severity: normal
> Tags: patch
> 
> If i link the simple program below with -lpthread, then valgrind
> reports a block of 32 bytes still-reachable from calloc within
> dlopen().
> 
> If i do not link with -lpthread, then valgrind reports no errors.

I've looked a bit into this, and it seems that the _dlerror_run() function
allocates a thread specific buffer which gets automatically freed once the
thread terminates. In fact when calling dlopen()/dlclose() inside a thread the
leak does not happen:

  #include <dlfcn.h>
  #include <pthread.h>

  void *leak(void *a) {
  	void *x;

  	x = dlopen("/usr/lib/x86_64-linux-gnu/libm.so", RTLD_LOCAL | RTLD_NOW);
  	dlclose(x);
  }

  int main(int argc, char *argv[]) {
  	pthread_t t;
  	void *ret;

  	pthread_create(&t, NULL, leak, NULL);
  	pthread_join(t, &ret);

  	/* leak(NULL); */

  	return 0;
  }

It seems a benign leak so adding a suppression shouldn't cause any problem. This
is the suppression I've added (yours is a little bit too specific):

  {
    dlopen() with -lpthread bug#700899
    Memcheck:Leak
    fun:calloc
    fun:_dlerror_run
    fun:dlopen@@GLIBC_2.2.5
  }

Cheers

-- 
perl -E '$_=q;$/= @{[@_]};and s;\S+;<inidehG ordnasselA>;eg;say~~reverse'
[signature.asc (application/pgp-signature, inline)]

Added tag(s) pending. Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Wed, 20 Feb 2013 10:30:07 GMT) (full text, mbox, link).


Removed tag(s) patch. Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Wed, 20 Feb 2013 10:30:07 GMT) (full text, mbox, link).


Reply sent to Alessandro Ghedini <ghedo@debian.org>:
You have taken responsibility. (Wed, 20 Feb 2013 11:06:11 GMT) (full text, mbox, link).


Notification sent to Daniel Kahn Gillmor <dkg@fifthhorseman.net>:
Bug acknowledged by developer. (Wed, 20 Feb 2013 11:06:11 GMT) (full text, mbox, link).


Message #19 received at 700899-close@bugs.debian.org (full text, mbox, reply):

From: Alessandro Ghedini <ghedo@debian.org>
To: 700899-close@bugs.debian.org
Subject: Bug#700899: fixed in valgrind 1:3.8.1-2
Date: Wed, 20 Feb 2013 11:03:10 +0000
Source: valgrind
Source-Version: 1:3.8.1-2

We believe that the bug you reported is fixed in the latest version of
valgrind, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 700899@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Alessandro Ghedini <ghedo@debian.org> (supplier of updated valgrind package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


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

Format: 1.8
Date: Wed, 20 Feb 2013 11:21:07 +0100
Source: valgrind
Binary: valgrind valgrind-dbg valgrind-mpi
Architecture: source amd64
Version: 1:3.8.1-2
Distribution: unstable
Urgency: low
Maintainer: Alessandro Ghedini <ghedo@debian.org>
Changed-By: Alessandro Ghedini <ghedo@debian.org>
Description: 
 valgrind   - instrumentation framework for building dynamic analysis tools
 valgrind-dbg - instrumentation framework for building dynamic analysis tools (de
 valgrind-mpi - instrumentation framework for building dynamic analysis tools (MP
Closes: 696694 696850 700899
Changes: 
 valgrind (1:3.8.1-2) unstable; urgency=low
 .
   [ Alessandro Ghedini ]
   * Bump Standards-Version to 3.9.4 (no changes needed)
   * Quote LD_LIBRARY_PATH in the wrapper script to avoid errors with spaced
     paths (LP: #880685)
   * Enable support for mipsel too (Closes: #696850)
   * Add suppression for dlopen() leak when linking with -lpthread
     (Closes: #700899)
 .
   [ Samuel Bronson ]
   * Allow building more than once from the same tree
     - Build and ship FAQ.txt from sources, since the bundled copy is deleted
       on "make clean"
   * Drop docs/valgrind.1 changes from 08_fix-spelling-in-manpage.patch
   * Add 10_unbreak-xinclude-in-manpage.patch to fix a broken XInclude
     (Closes: #696694)
Checksums-Sha1: 
 98fb0e5f3308c8de66967488a33b301f278d409d 2180 valgrind_3.8.1-2.dsc
 c8a0f1b22b4cbe70c504900008200910f78e339d 30205 valgrind_3.8.1-2.debian.tar.gz
 520cbaa8cf8c71dfdfb79cba6d1fea83f9717cc2 32202292 valgrind_3.8.1-2_amd64.deb
 34e39ea356bd896e29f55bfd4920c5271d703697 83889370 valgrind-dbg_3.8.1-2_amd64.deb
 cfdc64608f52c20e097ed698622ccdebfce3fce8 101828 valgrind-mpi_3.8.1-2_amd64.deb
Checksums-Sha256: 
 a38226b82aec9b002e3e69ff8e78aa44bf3d0a6602b2ce98311420ba67d90ef3 2180 valgrind_3.8.1-2.dsc
 8b57b54a68e77a52fd02ab91f5e46b1aafabd803fd975568fa911b7403770aac 30205 valgrind_3.8.1-2.debian.tar.gz
 95e7a63f76d9c550bc5d61e28667b81dce18569590dafd42b29edf11ac0bd823 32202292 valgrind_3.8.1-2_amd64.deb
 8b1a129698275c08969d77c17da4f2e53fdebc3cf8970c4a5c4d991faa95b75c 83889370 valgrind-dbg_3.8.1-2_amd64.deb
 16ed4c9d8e86abc1f79e33c97bf95d977ff9599ebfac5be05d89f1e46267736b 101828 valgrind-mpi_3.8.1-2_amd64.deb
Files: 
 58b243db29cdeaceec4fc10809aab916 2180 devel optional valgrind_3.8.1-2.dsc
 7067286f9f69ee7b32c3d173c9b71b1b 30205 devel optional valgrind_3.8.1-2.debian.tar.gz
 7df1c172325936c0de209f0feae95f6c 32202292 devel optional valgrind_3.8.1-2_amd64.deb
 05587f4ab95c114b1bc31d92083a0a02 83889370 debug extra valgrind-dbg_3.8.1-2_amd64.deb
 e8b5dd7088cc615bac0f1fa3058b42e3 101828 devel optional valgrind-mpi_3.8.1-2_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAEBAgAGBQJRJKWoAAoJEK+lG9bN5XPLqQQP/0x75+H24ZGTugILRQsASl/H
6tCfmghDqH7K5jhY2iygUI+zn7OQTSCfiyfIBGYIbd2n9+/WWDdfzDlRg196YlAM
L8FMvv7Pw+q/mASPp6I9JOcj9Juol2IN2k0QPBZ7g/0BQESC8kvGDVaAQyZNkYZ+
M51Hoa1T9y/6HdhT1Q0FUi1Nq6vP53Nnz3ZddgcPWswczrgf86EVqWo68xk9s16E
RQRTR+x0nov1ZAUxhu81S6e+cGvdgXCqcsjYFAUvoMGmm2sXhi9kZqbXbqcJ7AW/
/4OpcPr4VyC9D0ZNM5Av47d+6HTU0Wym8mboHjFb6tMGtcBi1vAOD5emyr4/dXH+
XgGHa9Po+EPn9OaRy91TYQ0BwmKyd26NcrMEEuyiQ0wnWRkt9H9YALQVt/ZuKM4M
qk2h9kv8kThL/8kpdDc0xTIe39f9UoPlnLR0l9DR4GHyRV2g3PyarJ+DcGsKbQ/p
Kwzt7Kf+J/qbTv37waT8tz89pLk57Xf3rQc59KQr4Oso19P16Gm4igJ4HiCfLSHE
rOtxWYcdytMUzdmivAYnltegfVYEzuipEAAGx9rNSlWIDbR6hxVr42P7JEQBRpHA
6HbM8FwPfRX4Hj+K5kQhtHzu//mp5L/dS9XTU71v45OZWiidgAP6gU63nrRfK3X+
0dELPFS2+wwVm6Vjrx7l
=LGN7
-----END PGP SIGNATURE-----




Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Thu, 21 Mar 2013 07:26:10 GMT) (full text, mbox, link).


Bug unarchived. Request was from Daniel Kahn Gillmor <dkg@fifthhorseman.net> to control@bugs.debian.org. (Mon, 07 Oct 2013 13:21:10 GMT) (full text, mbox, link).


Marked as found in versions 3.8.1-5. Request was from Daniel Kahn Gillmor <dkg@fifthhorseman.net> to control@bugs.debian.org. (Mon, 07 Oct 2013 13:21:11 GMT) (full text, mbox, link).


Added indication that 700899 affects libgnutls28 and p11-kit Request was from Daniel Kahn Gillmor <dkg@fifthhorseman.net> to control@bugs.debian.org. (Mon, 07 Oct 2013 13:21:11 GMT) (full text, mbox, link).


Marked as found in versions valgrind/1:3.8.1-5 and reopened. Request was from Daniel Kahn Gillmor <dkg@fifthhorseman.net> to control@bugs.debian.org. (Mon, 07 Oct 2013 13:42:04 GMT) (full text, mbox, link).


Merged 700899 725522 Request was from Daniel Kahn Gillmor <dkg@fifthhorseman.net> to control@bugs.debian.org. (Mon, 07 Oct 2013 13:42:10 GMT) (full text, mbox, link).


No longer marked as found in versions 3.8.1-5. Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Mon, 07 Oct 2013 15:03:04 GMT) (full text, mbox, link).


Disconnected #725522 from all other report(s). Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Sat, 12 Oct 2013 12:39:08 GMT) (full text, mbox, link).


No longer marked as found in versions valgrind/1:3.8.1-5. Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Sat, 12 Oct 2013 12:39:09 GMT) (full text, mbox, link).


Marked Bug as done Request was from Alessandro Ghedini <ghedo@debian.org> to control@bugs.debian.org. (Sat, 12 Oct 2013 12:57:10 GMT) (full text, mbox, link).


Notification sent to Daniel Kahn Gillmor <dkg@fifthhorseman.net>:
Bug acknowledged by developer. (Sat, 12 Oct 2013 12:57:11 GMT) (full text, mbox, link).


Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sun, 10 Nov 2013 07:44:38 GMT) (full text, mbox, link).


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Tue Sep 2 15:26:57 2025; Machine Name: berlioz

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU General Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.