[libvirt] [PATCH] bhyve: cleanup bhyveBuildNetArgStr error handling

Ján Tomko jtomko at redhat.com
Mon Nov 21 16:09:17 UTC 2016


On Mon, Nov 21, 2016 at 06:45:05PM +0300, Roman Bogorodskiy wrote:
>Use 'goto cleanup'-style error handling instead of explicitly
>freeing variables in every error path.
>---
> src/bhyve/bhyve_command.c | 39 +++++++++++++++++----------------------
> 1 file changed, 17 insertions(+), 22 deletions(-)
>
>diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
>index 022b03b..4914d98 100644
>--- a/src/bhyve/bhyve_command.c
>+++ b/src/bhyve/bhyve_command.c

>@@ -114,9 +104,14 @@ bhyveBuildNetArgStr(const virDomainDef *def,
>     virCommandAddArgFormat(cmd, "%d:0,virtio-net,%s,mac=%s",
>                            net->info.addr.pci.slot,
>                            realifname, virMacAddrFormat(&net->mac, macaddr));
>+
>+    ret = 0;
>+ cleanup:
>+    VIR_FREE(brname);

Okay, brname was leaked before.

>+    VIR_FREE(net->ifname);

But freeing stuff from the virDomainNetDef structure on success seems
wrong.

Previously, all the error codepaths except
  if (VIR_STRDUP(realifname, "tap0") < 0)
on a dry run left net->ifname at NULL, but after this patch it seems
the network will not be cleaned up later even though it was created
successfully.

ACK if you wrap it in:
  if (ret < 0)

Jan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20161121/cd17324c/attachment-0001.sig>


More information about the libvir-list mailing list