<tt><font size=2>Martin Kletzander <mkletzan@redhat.com> wrote on
03/19/2014 09:13:51 AM:<br>
<br>
> <br>
> On Tue, Mar 18, 2014 at 09:45:14PM -0400, Stefan Berger wrote:<br>
> > From: Stefan Berger <stefanb@linux.vnet.ibm.com><br>
> ><br>
> > </font></tt><a href="https://bugzilla.redhat.com/show_bug.cgi?id=1071181"><tt><font size=2>https://bugzilla.redhat.com/show_bug.cgi?id=1071181</font></tt></a><tt><font size=2><br>
> ><br>
> > Commit 49b59a15 fixed one problem but masks another one related
to pointer<br>
> > freeing.<br>
> ><br>
> > Use virAtomicIntGet() to test for 0 rather than trying to test
for 'true'<br>
> > after  virAtomicIntDecAndTest().<br>
> ><br>
> > Avoid putting of the virNWFilterSnoopReq once the thread has
been started.<br>
> ><br>
> > Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com><br>
> > ---<br>
> >  src/nwfilter/nwfilter_dhcpsnoop.c | 11 +++++++++--<br>
> >  1 file changed, 9 insertions(+), 2 deletions(-)<br>
> ><br>
> > diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/<br>
> nwfilter_dhcpsnoop.c<br>
> > index d2a8062..32ca304 100644<br>
> > --- a/src/nwfilter/nwfilter_dhcpsnoop.c<br>
> > +++ b/src/nwfilter/nwfilter_dhcpsnoop.c<br>
> > @@ -720,7 +720,10 @@ virNWFilterSnoopReqPut(virNWFilterSnoopReqPtr
req)<br>
> ><br>
> >      virNWFilterSnoopLock();<br>
> ><br>
> > -    if (virAtomicIntDecAndTest(&req->refctr))
{<br>
> > +    virAtomicIntDecAndTest(&req->refctr);<br>
> > +<br>
> > +    /* make sure it's 0; virAtomitIntDecAndTest may
return true on '1' */<br>
> > +    if (virAtomicIntGet(&req->refctr) == 0)
{<br>
> <br>
> NACK, using two atomic functions, you are making this non-atomic.<br>
> between these two atomic operations many things can happen an it's
not<br>
> what you want I bet.  The virAtomicIntDecAndTest() uses<br>
> __sync_fetch_and_sub(atomic, 1) and compares it to 1, that's true,
but<br>
> since it is fetch_and_sub (and not the other way around, the value<br>
> being compared to 1 is the value that the atomic had before it was<br>
> decremented.  That means it returns 1 (true) if and only if the<br>
> current value is 0.  virAtomicIntDecAndTest() is what you really
want<br>
> and should use here.</font></tt>
<br>
<br><tt><font size=2>Right. I initially thought there was something wrong
in this part here until I found the double free error is related to the
other part. So this part you comment on doesn't need to be changed.</font></tt>
<br>
<br><tt><font size=2>   Stefan</font></tt>
<br>