virDomainFree has it's quirks (does not like NULL pointers, resets libvirt errors). Replace it by a virsh helper which will allow us to centrally fix issues with it. The syntax-check rule will prohibit new uses of virDomainFree. --- cfg.mk | 8 ++ tools/virsh-domain-monitor.c | 36 ++++---- tools/virsh-domain.c | 216 ++++++++++++++++++++----------------------- tools/virsh-snapshot.c | 24 ++--- tools/virsh-util.c | 10 ++ tools/virsh-util.h | 3 + 6 files changed, 149 insertions(+), 148 deletions(-) diff --git a/cfg.mk b/cfg.mk index cc174a3cc..1ff87f445 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1014,6 +1014,14 @@ sc_gettext_init: halt='the above files do not call virGettextInitialize' \ $(_sc_search_regexp) +#Ensure that virsh uses the wrappers on top of the object freeing APIs +sc_prohibit_obj_free_apis_in_virsh: + @prohibit='\virDomainFree\b' \ + in_vc_files='\virsh.*\.[ch]$$' \ + exclude='sc_prohibit_obj_free_apis_in_virsh' \ + halt='avoid using virDomainFree in virsh, use virsh-prefixed wrappers instead' \ + $(_sc_search_regexp) + # We don't use this feature of maint.mk. prev_version_file = /dev/null diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 5215ac6f9..92995ad7d 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -381,7 +381,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -432,7 +432,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -554,7 +554,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xmldoc); VIR_FREE(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -648,7 +648,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(interfaces); - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(xml); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); @@ -758,7 +758,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xpath); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -811,7 +811,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -997,7 +997,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(params); - virDomainFree(dom); + virshDomainFree(dom); return ret; } #undef DOMBLKSTAT_LEGACY_PRINT @@ -1071,7 +1071,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1132,7 +1132,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(disks); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1241,7 +1241,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) memset(&secmodel, 0, sizeof(secmodel)); if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) { if (last_error->code != VIR_ERR_NO_SUPPORT) { - virDomainFree(dom); + virshDomainFree(dom); return false; } else { vshResetLibvirtError(); @@ -1254,12 +1254,12 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) /* Security labels are only valid for active domains */ if (VIR_ALLOC(seclabel) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } if (virDomainGetSecurityLabel(dom, seclabel) == -1) { - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(seclabel); return false; } else { @@ -1271,7 +1271,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(seclabel); } } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1323,7 +1323,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1427,7 +1427,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1493,7 +1493,7 @@ virshDomainListFree(virshDomainListPtr domlist) if (domlist && domlist->domains) { for (i = 0; i < domlist->ndomains; i++) { if (domlist->domains[i]) - virDomainFree(domlist->domains[i]); + virshDomainFree(domlist->domains[i]); } VIR_FREE(domlist->domains); } @@ -1689,7 +1689,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int flags) remove_entry: /* the domain has to be removed as it failed one of the filters */ - virDomainFree(list->domains[i]); + virshDomainFree(list->domains[i]); list->domains[i] = NULL; deleted++; } @@ -2294,7 +2294,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(ifaces); - virDomainFree(dom); + virshDomainFree(dom); return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4e4df5b4f..ba179c89c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -218,7 +218,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -700,8 +700,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } @@ -1011,8 +1010,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xml); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } @@ -1056,7 +1054,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Failed to mark domain %s as autostarted"), name); else vshError(ctl, _("Failed to unmark domain %s as autostarted"), name); - virDomainFree(dom); + virshDomainFree(dom); return false; } @@ -1065,7 +1063,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd) else vshPrintExtra(ctl, _("Domain %s unmarked as autostarted\n"), name); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -1379,8 +1377,7 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -1577,7 +1574,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -2086,7 +2083,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2394,7 +2391,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(xmlstr); virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2638,8 +2635,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) ret = virshBlockJobInfo(ctl, dom, path, raw, bytes); cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -2784,7 +2780,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virshBlockJobWaitFree(bjWait); return ret; } @@ -2848,7 +2844,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd) ret = true; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -2942,7 +2938,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) ret = cmdRunConsole(ctl, dom, name, flags); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } #endif /* WIN32 */ @@ -3123,7 +3119,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(xml_buf); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3314,7 +3310,7 @@ cmdDomIftune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -3359,7 +3355,7 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3438,7 +3434,7 @@ cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3485,7 +3481,7 @@ cmdDomPMWakeup(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -3905,7 +3901,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_nodes); xmlFreeDoc(doc); xmlXPathFreeContext(ctxt); - virDomainFree(dom); + virshDomainFree(dom); return ret; error: @@ -4085,7 +4081,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(fds); return ret; } @@ -4183,8 +4179,7 @@ doSave(void *opaque) out: pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(xml); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -4344,7 +4339,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s saved to %s\n"), name, to); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -4607,8 +4602,7 @@ doManagedsave(void *opaque) out: pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -4651,7 +4645,7 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s state saved by libvirt\n"), name); cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return ret; @@ -4708,7 +4702,7 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -4943,7 +4937,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); virTypedParamsFree(updates, nupdates); - virDomainFree(dom); + virshDomainFree(dom); return ret_val; } @@ -5145,7 +5139,7 @@ doDump(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -5191,7 +5185,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("\nDomain %s dumped to %s\n"), name, to); cleanup: - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return ret; @@ -5330,7 +5324,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - virDomainFree(dom); + virshDomainFree(dom); if (st) virStreamFree(st); VIR_FORCE_CLOSE(fd); @@ -5399,7 +5393,7 @@ cmdSetUserPassword(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } /* @@ -5437,7 +5431,7 @@ cmdResume(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -5520,8 +5514,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virStringListFree(modes); return ret; } @@ -5600,8 +5593,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - if (dom) - virDomainFree(dom); + virshDomainFree(dom); virStringListFree(modes); return ret; } @@ -5641,7 +5633,7 @@ cmdReset(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -5943,7 +5935,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); virTypedParamsFree(params, nparams); return ret; @@ -5982,7 +5974,7 @@ cmdDomjobabort(vshControl *ctl, const vshCmd *cmd) if (virDomainAbortJob(dom) < 0) ret = false; - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6183,7 +6175,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6437,7 +6429,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumaps); VIR_FREE(cpuinfo); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6653,7 +6645,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6714,13 +6706,13 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) return false; if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } query = !cpulist; if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } @@ -6757,7 +6749,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6853,7 +6845,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -6939,7 +6931,7 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7021,7 +7013,7 @@ cmdSetvcpu(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7079,7 +7071,7 @@ cmdDomblkthreshold(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7155,7 +7147,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(info); cleanup: - virDomainFree(dom); + virshDomainFree(dom); return niothreads >= 0; } @@ -7237,7 +7229,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(cpumap); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7302,7 +7294,7 @@ cmdIOThreadAdd(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7367,7 +7359,7 @@ cmdIOThreadDel(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -7758,7 +7750,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; failed_stats: @@ -7854,7 +7846,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (console) cmdRunConsole(ctl, dom, NULL, 0); #endif - virDomainFree(dom); + virshDomainFree(dom); ret = true; cleanup: @@ -7913,7 +7905,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (dom != NULL) { vshPrintExtra(ctl, _("Domain %s defined from %s\n"), virDomainGetName(dom), from); - virDomainFree(dom); + virshDomainFree(dom); } else { vshError(ctl, _("Failed to define domain from %s"), from); ret = false; @@ -7970,7 +7962,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8137,8 +8129,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) unlink(tmp); VIR_FREE(tmp); } - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8281,7 +8272,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8316,7 +8307,7 @@ cmdInjectNMI(vshControl *ctl, const vshCmd *cmd) if (virDomainInjectNMI(dom, 0) < 0) ret = false; - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8412,7 +8403,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8517,7 +8508,7 @@ cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8585,7 +8576,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } kibibytes = VIR_DIV_UP(bytes, 1024); @@ -8598,7 +8589,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8666,7 +8657,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) else max = ULONG_MAX; if (vshCommandOptScaledInt(ctl, cmd, "size", &bytes, 1024, max) < 0) { - virDomainFree(dom); + virshDomainFree(dom); return false; } kibibytes = VIR_DIV_UP(bytes, 1024); @@ -8683,7 +8674,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) } } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -8854,7 +8845,7 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -8993,7 +8984,7 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9126,7 +9117,7 @@ cmdNumatune(vshControl * ctl, const vshCmd * cmd) cleanup: virTypedParamsFree(params, nparams); - virDomainFree(dom); + virshDomainFree(dom); return ret; save_error: @@ -9220,7 +9211,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) VIR_FREE(result); VIR_FREE(monitor_cmd); virJSONValueFree(pretty); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9384,8 +9375,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >= 0 && virConnectDomainQemuMonitorEventDeregister(priv->conn, eventId) < 0) ret = false; - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9431,7 +9421,7 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain %s attached to pid %u\n"), virDomainGetName(dom), pid_value); - virDomainFree(dom); + virshDomainFree(dom); ret = true; cleanup: @@ -9555,8 +9545,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(result); VIR_FREE(guest_agent_cmd); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9697,8 +9686,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(seclabel); VIR_FREE(secmodel); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); VIR_FREE(cmdargv); return ret; } @@ -9769,7 +9757,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) ret = false; } - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9915,7 +9903,7 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd) return false; vshPrint(ctl, "%s\n", virDomainGetName(dom)); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -9962,7 +9950,7 @@ cmdDomrename(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -9999,7 +9987,7 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", "-"); else vshPrint(ctl, "%d\n", id); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -10036,7 +10024,7 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, "%s", _("failed to get domain UUID")); - virDomainFree(dom); + virshDomainFree(dom); return true; } @@ -10466,7 +10454,7 @@ doMigrate(void *opaque) virDomainPtr ddom = NULL; if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) { - virDomainFree(ddom); + virshDomainFree(ddom); ret = '0'; } } @@ -10475,8 +10463,7 @@ doMigrate(void *opaque) pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: virTypedParamsFree(params, nparams); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); return; @@ -10632,7 +10619,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) virConnectClose(data.dconn); if (iterEvent != -1) virConnectDomainEventDeregisterAny(priv->conn, iterEvent); - virDomainFree(dom); + virshDomainFree(dom); VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[1]); return functionReturn; @@ -10684,7 +10671,7 @@ cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10741,7 +10728,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10788,7 +10775,7 @@ cmdMigrateSetMaxSpeed(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10828,7 +10815,7 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd) ret = true; done: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -10870,7 +10857,7 @@ cmdMigratePostCopy(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11127,7 +11114,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(output); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11208,7 +11195,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(listen_addr); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11264,7 +11251,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeObject(obj); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11307,7 +11294,7 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) error: VIR_FREE(hostname); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11504,7 +11491,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return funcRet; } @@ -11586,7 +11573,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -11772,7 +11759,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(doc_live); VIR_FREE(doc_config); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -12129,7 +12116,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) xmlFreeNode(disk_node); VIR_FREE(disk_xml); VIR_FREE(doc); - virDomainFree(dom); + virshDomainFree(dom); return functionReturn; } @@ -12196,10 +12183,8 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - if (dom) - virDomainFree(dom); - if (dom_edited) - virDomainFree(dom_edited); + virshDomainFree(dom); + virshDomainFree(dom_edited); return ret; } @@ -13087,8 +13072,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) } VIR_FREE(data); } - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13253,7 +13237,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) VIR_FREE(doc); xmlFreeNode(disk_node); VIR_FREE(disk_xml); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13306,7 +13290,7 @@ cmdDomFSTrim(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -13359,7 +13343,7 @@ cmdDomFSFreeze(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virDomainFree(dom); + virshDomainFree(dom); return ret >= 0; } @@ -13412,7 +13396,7 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(mountpoints); - virDomainFree(dom); + virshDomainFree(dom); return ret >= 0; } @@ -13472,7 +13456,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) } cleanup: - virDomainFree(dom); + virshDomainFree(dom); return ret >= 0; } diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 46e2cbb24..5af9a7d7a 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -210,8 +210,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(buffer); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -454,7 +453,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) cleanup: virBufferFreeAndReset(&buf); VIR_FREE(buffer); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -606,7 +605,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) virDomainSnapshotFree(edited); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -720,7 +719,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1008,7 +1007,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(parent); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1647,7 +1646,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); VIR_FREE(doc); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1711,7 +1710,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1771,8 +1770,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd) VIR_FREE(parent); if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1857,8 +1855,7 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd) cleanup: if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } @@ -1940,8 +1937,7 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd) cleanup: if (snapshot) virDomainSnapshotFree(snapshot); - if (dom) - virDomainFree(dom); + virshDomainFree(dom); return ret; } diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 5c99655fb..5fdb40855 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -150,3 +150,13 @@ virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED, return safewrite(*fd, bytes, nbytes); } + + +void +virshDomainFree(virDomainPtr dom) +{ + if (!dom) + return; + + virDomainFree(dom); /* sc_prohibit_obj_free_apis_in_virsh */ +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 132bf0b4b..78f7a0ea9 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -38,6 +38,9 @@ virshCommandOptDomain(vshControl *ctl, const vshCmd *cmd, const char **name); +void +virshDomainFree(virDomainPtr dom); + int virshDomainState(vshControl *ctl, virDomainPtr dom, -- 2.12.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list