Eric Blake
2018-Nov-08 03:02 UTC
[Libguestfs] [nbdkit PATCH] test-layers: Avoid thread leak
Running 'make check' under a ThreadSanitizer build complains that test-layers leaks a pthread; while harmless, it is also an easy fix, by detaching the thread to ensure it gets cleaned up. Signed-off-by: Eric Blake <eblake@redhat.com> --- tests/test-layers.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test-layers.c b/tests/test-layers.c index 00e6031..7b58699 100644 --- a/tests/test-layers.c +++ b/tests/test-layers.c @@ -152,6 +152,12 @@ main (int argc, char *argv[]) perror ("pthread_create"); exit (EXIT_FAILURE); } + err = pthread_detach(&thread); + if (err) { + errno = err; + perror ("pthread_detach"); + exit (EXIT_FAILURE); + } /* Note for the purposes of this test we're not very careful about * checking for errors (except for the bare minimum) or handling the -- 2.17.2
Eric Blake
2018-Nov-08 03:16 UTC
Re: [Libguestfs] [nbdkit PATCH] test-layers: Avoid thread leak
On 11/7/18 9:02 PM, Eric Blake wrote:> Running 'make check' under a ThreadSanitizer build complains that > test-layers leaks a pthread; while harmless, it is also an easy > fix, by detaching the thread to ensure it gets cleaned up. > > Signed-off-by: Eric Blake <eblake@redhat.com> > --- > tests/test-layers.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/tests/test-layers.c b/tests/test-layers.c > index 00e6031..7b58699 100644 > --- a/tests/test-layers.c > +++ b/tests/test-layers.c > @@ -152,6 +152,12 @@ main (int argc, char *argv[]) > perror ("pthread_create"); > exit (EXIT_FAILURE); > } > + err = pthread_detach(&thread);It helps if I don't send an email prior to amending the commit to contain what actually passed testing :) This line should be: err = pthread_detach (thread);> + if (err) { > + errno = err; > + perror ("pthread_detach"); > + exit (EXIT_FAILURE); > + } > > /* Note for the purposes of this test we're not very careful about > * checking for errors (except for the bare minimum) or handling the >-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2018-Nov-08 10:50 UTC
Re: [Libguestfs] [nbdkit PATCH] test-layers: Avoid thread leak
On Wed, Nov 07, 2018 at 09:16:37PM -0600, Eric Blake wrote:> On 11/7/18 9:02 PM, Eric Blake wrote: > >Running 'make check' under a ThreadSanitizer build complains that > >test-layers leaks a pthread; while harmless, it is also an easy > >fix, by detaching the thread to ensure it gets cleaned up. > > > >Signed-off-by: Eric Blake <eblake@redhat.com> > >--- > > tests/test-layers.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > >diff --git a/tests/test-layers.c b/tests/test-layers.c > >index 00e6031..7b58699 100644 > >--- a/tests/test-layers.c > >+++ b/tests/test-layers.c > >@@ -152,6 +152,12 @@ main (int argc, char *argv[]) > > perror ("pthread_create"); > > exit (EXIT_FAILURE); > > } > >+ err = pthread_detach(&thread); > > It helps if I don't send an email prior to amending the commit to > contain what actually passed testing :) This line should be: > > err = pthread_detach (thread); > > >+ if (err) { > >+ errno = err; > >+ perror ("pthread_detach"); > >+ exit (EXIT_FAILURE); > >+ } > > > > /* Note for the purposes of this test we're not very careful about > > * checking for errors (except for the bare minimum) or handling the > >ACK, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Apparently Analagous Threads
- [nbdkit PATCH] test-layers: Avoid thread leak
- libasan bug: pthread_create never returns
- [PATCH libnbd v2 4/4] examples: Add concurrent writer example.
- [PATCH libnbd discussion only 5/5] examples: Add concurrent writer example.
- [PATCH v3 REPOST 5/5] threads: Add a test.