[libvirt] [PATCH] Merge all returns paths from dispatcher into single path
Eric Blake
eblake at redhat.com
Wed Apr 13 19:29:48 UTC 2011
On 04/13/2011 12:12 PM, Daniel P. Berrange wrote:
> The dispatcher functions have numerous places where they
> return to the caller. This leads to duplicated cleanup
> code, often resulting in memory leaks. It makes it harder
> to ensure that errors are dispatched before freeing objects,
> which may overwrite the original error.
>
> The standard pattern is now
>
> remoteDispatchXXX(...) {
> int rv = -1;
>
> ....
> if (XXX < 0)
> goto cleanup;
> ...
> if (XXXX < 0)
> goto cleanup;
> ...
>
> rv = 0;
> cleanup:
> if (rv < 0)
> remoteDispatchError(rerr);
> ...free all other stuff..
> return rv;
> }
>
> * daemon/remote.c: Centralize all cleanup paths
> * daemon/stream.c: s/remoteDispatchConnError/remoteDispatchError/
> * daemon/dispatch.c, daemon/dispatch.h: Replace
> remoteDispatchConnError with remoteDispatchError
> removing unused virConnectPtr
Sounds good.
>
>
> NB this was a tedious manual conversion of the code, so it
> has potential for errors....
Indeed - so I'll be looking at it closely; just getting this email out
now to avoid anyone else spending duplicate time on it.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110413/6c3aa7cd/attachment-0001.sig>
More information about the libvir-list
mailing list