]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: standardize return from functions calling virNetlinkCommand
authorLaine Stump <laine@laine.org>
Wed, 7 Mar 2012 17:44:56 +0000 (12:44 -0500)
committerLaine Stump <laine@laine.org>
Thu, 8 Mar 2012 21:58:34 +0000 (16:58 -0500)
commit0208face59686fb4e8a43f6bb9b8a8770e26d0eb
tree69ca1c461c5eaf4ac461ac4805736fca1976cfa6
parentf985773d06ed17cd699907ac8b271864c8b67870
util: standardize return from functions calling virNetlinkCommand

There are several functions that call virNetlinkCommand, and they all
follow a common pattern, with three exit labels: err_exit (or
cleanup), malformed_resp, and buffer_too_small. All three of these
labels do their own cleanup and have their own return. However, the
malformed_resp label usually frees the same items as the
cleanup/err_exit label, and the buffer_too_small label just doesn't
free recvbuf (because it's known to always be NULL at the time we goto
buffer_too_small.

In order to simplify and standardize the code, I've made the following
changes to all of these functions:

1) err_exit is replaced with the more libvirt-ish "cleanup", which
   makes sense because in all cases this code is also executed in the
   case of success, so labelling it err_exit may be confusing.

2) rc is initialized to -1, and set to 0 just before the cleanup
   label. Any code that currently sets rc = -1 is made to instead goto
   cleanup.

3) malformed_resp and buffer_too_small just log their error and goto
   cleanup. This gives us a single return path, and a single place to
   free up resources.

4) In one instance, rather then logging an error immediately, a char*
   msg was pointed to an error string, then goto cleanup (and cleanup
   would log an error if msg != NULL). It takes no more lines of code
   to just log the message as we encounter it.

This patch should have 0 functional effects.
src/util/virnetdev.c
src/util/virnetdevmacvlan.c
src/util/virnetdevvportprofile.c