Pino Toscano
2014-Aug-08 15:21 UTC
[Libguestfs] [PATCH] df: unlock retire_mutex on early exit
If pthread_cond_wait fails and the thread worker ends, make sure to unlock retire_mutex, which has been locked for the condition. The return value of pthread_mutex_unlock is ignored, as there's nothing that can be done with it at that point. --- df/parallel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/df/parallel.c b/df/parallel.c index 047735e..6d2e1cf 100644 --- a/df/parallel.c +++ b/df/parallel.c @@ -33,6 +33,8 @@ #include <libvirt/virterror.h> #endif +#include "ignore-value.h" + #include "guestfs.h" #include "guestfs-internal-frontend.h" #include "options.h" @@ -224,6 +226,7 @@ worker_thread (void *thread_data_vp) if (err != 0) { thread_failure ("pthread_cond_wait", err); thread_data->r = -1; + ignore_value (pthread_mutex_unlock (&retire_mutex)); return &thread_data->r; } } -- 1.9.3
Richard W.M. Jones
2014-Aug-08 18:32 UTC
Re: [Libguestfs] [PATCH] df: unlock retire_mutex on early exit
On Fri, Aug 08, 2014 at 05:21:17PM +0200, Pino Toscano wrote:> If pthread_cond_wait fails and the thread worker ends, make sure to > unlock retire_mutex, which has been locked for the condition. > > The return value of pthread_mutex_unlock is ignored, as there's nothing > that can be done with it at that point. > --- > df/parallel.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/df/parallel.c b/df/parallel.c > index 047735e..6d2e1cf 100644 > --- a/df/parallel.c > +++ b/df/parallel.c > @@ -33,6 +33,8 @@ > #include <libvirt/virterror.h> > #endif > > +#include "ignore-value.h" > + > #include "guestfs.h" > #include "guestfs-internal-frontend.h" > #include "options.h" > @@ -224,6 +226,7 @@ worker_thread (void *thread_data_vp) > if (err != 0) { > thread_failure ("pthread_cond_wait", err); > thread_data->r = -1; > + ignore_value (pthread_mutex_unlock (&retire_mutex)); > return &thread_data->r; > } > } > -- > 1.9.3ACK. 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/