By making use of GNU C's cleanup attribute handled by the VIR_AUTOCLOSE macro, many of the VIR_FORCE_CLOSE calls can be dropped, which in turn leads to getting rid of many of our cleanup sections. Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/uml/uml_conf.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index f116e61..da0dc69 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -112,14 +112,14 @@ umlConnectTapDevice(virDomainDefPtr vm, const char *bridge) { bool template_ifname = false; - int tapfd = -1; + VIR_AUTOCLOSE(tapfd); if (!net->ifname || STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0) - goto error; + return -1; /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; } @@ -133,23 +133,18 @@ umlConnectTapDevice(virDomainDefPtr vm, VIR_NETDEV_TAP_CREATE_PERSIST) < 0) { if (template_ifname) VIR_FREE(net->ifname); - goto error; + return -1; } if (net->filter) { if (virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) < 0) { if (template_ifname) VIR_FREE(net->ifname); - goto error; + return -1; } } - VIR_FORCE_CLOSE(tapfd); return 0; - - error: - VIR_FORCE_CLOSE(tapfd); - return -1; } static char * -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list