Rather than have vnc be a variable within the if, promote it to the top, then adjust the code to use the error label to call virDomainGraphicsDefFree
Signed-off-by: John Ferlan <jfer...@redhat.com> --- src/qemu/qemu_command.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d7f19f3..7b5a36f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -12999,6 +12999,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, int nvirtiodisk = 0; qemuDomainCmdlineDefPtr cmd = NULL; virDomainDiskDefPtr disk = NULL; + virDomainGraphicsDefPtr vnc = NULL; const char *ceph_args = qemuFindEnv(progenv, "CEPH_ARGS"); bool have_sdl = false; @@ -13100,7 +13101,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, arg++; if (STREQ(arg, "-vnc")) { - virDomainGraphicsDefPtr vnc; char *tmp; WANT_VALUE(); if (VIR_ALLOC(vnc) < 0) @@ -13109,10 +13109,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps, if (STRPREFIX(val, "unix:")) { /* -vnc unix:/some/big/path */ - if (VIR_STRDUP(vnc->data.vnc.socket, val + 5) < 0) { - virDomainGraphicsDefFree(vnc); + if (VIR_STRDUP(vnc->data.vnc.socket, val + 5) < 0) goto error; - } } else { /* * -vnc 127.0.0.1:4 @@ -13126,7 +13124,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, sep = "]:"; tmp = strstr(val, sep); if (!tmp) { - virDomainGraphicsDefFree(vnc); virReportError(VIR_ERR_INTERNAL_ERROR, _("missing VNC port number in '%s'"), val); goto error; @@ -13134,7 +13131,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, port = tmp + strlen(sep); if (virStrToLong_i(port, &opts, 10, &vnc->data.vnc.port) < 0) { - virDomainGraphicsDefFree(vnc); virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse VNC port '%s'"), port); goto error; @@ -13145,18 +13141,14 @@ qemuParseCommandLine(virCapsPtr qemuCaps, else virDomainGraphicsListenSetAddress(vnc, 0, val, tmp-val, true); - if (!virDomainGraphicsListenGetAddress(vnc, 0)) { - virDomainGraphicsDefFree(vnc); + if (!virDomainGraphicsListenGetAddress(vnc, 0)) goto error; - } if (*opts == ',') { char *orig_opts; - if (VIR_STRDUP(orig_opts, opts + 1) < 0) { - virDomainGraphicsDefFree(vnc); + if (VIR_STRDUP(orig_opts, opts + 1) < 0) goto error; - } opts = orig_opts; while (opts && *opts) { @@ -13177,7 +13169,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, _("cannot parse VNC " "WebSocket port '%s'"), websocket); - virDomainGraphicsDefFree(vnc); VIR_FREE(orig_opts); goto error; } @@ -13198,7 +13189,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown vnc display sharing policy '%s'"), sharePolicy); - virDomainGraphicsDefFree(vnc); VIR_FREE(orig_opts); goto error; } else { @@ -13207,7 +13197,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps, } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing vnc sharing policy")); - virDomainGraphicsDefFree(vnc); VIR_FREE(orig_opts); goto error; } @@ -13221,10 +13210,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps, vnc->data.vnc.autoport = false; } - if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, vnc) < 0) { - virDomainGraphicsDefFree(vnc); + if (VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, vnc) < 0) goto error; - } } else if (STREQ(arg, "-sdl")) { have_sdl = true; } else if (STREQ(arg, "-m")) { @@ -13991,6 +13978,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, return def; error: + virDomainGraphicsDefFree(vnc); virDomainDiskDefFree(disk); qemuDomainCmdlineDefFree(cmd); virDomainDefFree(def); -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list