On 07/11/2012 07:35 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Make all the virNetClient* objects use virObject APIs for
reference counting
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
@@ -286,19 +294,22 @@ static virNetClientPtr
virNetClientNew(virNetSocketPtr sock,
- if (virMutexInit(&client->lock) < 0)
+ if (virMutexInit(&client->lock) < 0) {
+ VIR_FREE(client);
goto error;
Hmm - this discards the fact that client has a ref-count of 1, and thus
fails to poison that memory (one of the benefits of always going through
unref is that that poisoning helps detect use-after-free bugs).
Thankfully, though, there is no other allocated memory owned by 'client'
at this point in time, so skipping the dispose method is not technically
a leak; furthermore, since the dispose method tries to call
virMutexDestroy but we know the mutex failed to initialize, I think it's
the best we can do. You made me think about this, but in the end I
agree it is right, even though it looks fishy.
ACK. Overall, the series looks like a good improvement (anything that
can cause a net reduction in lines of code _and_ speed up execution with
fewer lock points all while remaining atomically correct is awesome); I
did point out some flaws through the series, and look forward to
reviewing v2 (or more likely, the interdiff between v1 and v2).
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org