From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> The VIR_FREE() macro will cast away any const-ness. This masked a number of places where we passed a 'const char *' string to VIR_FREE. Fortunately in all of these cases, the variable was not in fact const data, but a heap allocated string. Fix all the variable declarations to reflect this. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/conf/domain_conf.c | 30 +++++++++++++++--------------- src/conf/netdev_vlan_conf.c | 4 ++-- src/conf/nwfilter_conf.c | 3 ++- src/node_device/node_device_udev.c | 2 +- src/nwfilter/nwfilter_gentech_driver.c | 2 +- src/qemu/qemu_command.c | 33 +++++++++++++++++++-------------- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 4 ++-- src/rpc/virnetsshsession.c | 34 +++++++++++++++++++++------------- src/storage/storage_backend.c | 2 +- src/storage/storage_driver.c | 2 +- src/util/vircommand.c | 9 ++++----- src/util/virlog.c | 4 ++-- tools/virsh-domain.c | 19 ++++++++++--------- 14 files changed, 82 insertions(+), 68 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f8fbf79..678f8ca 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6745,9 +6745,9 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def, { int ret = -1; unsigned int port; - const char *targetType = virXMLPropString(cur, "type"); - const char *addrStr = NULL; - const char *portStr = NULL; + char *targetType = virXMLPropString(cur, "type"); + char *addrStr = NULL; + char *portStr = NULL; if ((def->targetType = virDomainChrTargetTypeFromString(def, def->deviceType, @@ -8161,7 +8161,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if (xmlStrEqual(cur->name, BAD_CAST "channel")) { - const char *name, *mode; + char *name, *mode; int nameval, modeval; name = virXMLPropString(cur, "name"); mode = virXMLPropString(cur, "mode"); @@ -8195,7 +8195,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.channels[nameval] = modeval; } else if (xmlStrEqual(cur->name, BAD_CAST "image")) { - const char *compression = virXMLPropString(cur, "compression"); + char *compression = virXMLPropString(cur, "compression"); int compressionVal; if (!compression) { @@ -8216,7 +8216,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.image = compressionVal; } else if (xmlStrEqual(cur->name, BAD_CAST "jpeg")) { - const char *compression = virXMLPropString(cur, "compression"); + char *compression = virXMLPropString(cur, "compression"); int compressionVal; if (!compression) { @@ -8237,7 +8237,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.jpeg = compressionVal; } else if (xmlStrEqual(cur->name, BAD_CAST "zlib")) { - const char *compression = virXMLPropString(cur, "compression"); + char *compression = virXMLPropString(cur, "compression"); int compressionVal; if (!compression) { @@ -8258,7 +8258,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.zlib = compressionVal; } else if (xmlStrEqual(cur->name, BAD_CAST "playback")) { - const char *compression = virXMLPropString(cur, "compression"); + char *compression = virXMLPropString(cur, "compression"); int compressionVal; if (!compression) { @@ -8279,7 +8279,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.playback = compressionVal; } else if (xmlStrEqual(cur->name, BAD_CAST "streaming")) { - const char *mode = virXMLPropString(cur, "mode"); + char *mode = virXMLPropString(cur, "mode"); int modeVal; if (!mode) { @@ -8299,7 +8299,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.streaming = modeVal; } else if (xmlStrEqual(cur->name, BAD_CAST "clipboard")) { - const char *copypaste = virXMLPropString(cur, "copypaste"); + char *copypaste = virXMLPropString(cur, "copypaste"); int copypasteVal; if (!copypaste) { @@ -8319,7 +8319,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, def->data.spice.copypaste = copypasteVal; } else if (xmlStrEqual(cur->name, BAD_CAST "mouse")) { - const char *mode = virXMLPropString(cur, "mode"); + char *mode = virXMLPropString(cur, "mode"); int modeVal; if (!mode) { @@ -8511,9 +8511,9 @@ virDomainRNGDefParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt, unsigned int flags) { - const char *model = NULL; - const char *backend = NULL; - const char *type = NULL; + char *model = NULL; + char *backend = NULL; + char *type = NULL; virDomainRNGDefPtr def; xmlNodePtr save = ctxt->node; xmlNodePtr *backends = NULL; @@ -15197,7 +15197,7 @@ virDomainChrDefFormat(virBufferPtr buf, return -1; } - const char *addr = virSocketAddrFormat(def->target.addr); + char *addr = virSocketAddrFormat(def->target.addr); if (addr == NULL) return -1; diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c index 60d9eb8..24e1000 100644 --- a/src/conf/netdev_vlan_conf.c +++ b/src/conf/netdev_vlan_conf.c @@ -36,8 +36,8 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de { int ret = -1; xmlNodePtr save = ctxt->node; - const char *trunk = NULL; - const char *nativeMode = NULL; + char *trunk = NULL; + char *nativeMode = NULL; xmlNodePtr *tagNodes = NULL; int nTags; size_t i; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index a3901d3..00e74eb 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2432,7 +2432,8 @@ static const char * virNWFilterIsAllowedChain(const char *chainname) { enum virNWFilterChainSuffixType i; - const char *name, *msg; + const char *name; + char *msg; virBuffer buf = VIR_BUFFER_INITIALIZER; bool printed = false; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 67fcc58..785c2fa 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -367,7 +367,7 @@ udevLogFunction(struct udev *udev ATTRIBUTE_UNUSED, va_list args) { virBuffer buf = VIR_BUFFER_INITIALIZER; - const char *format = NULL; + char *format = NULL; virBufferAdd(&buf, fmt, -1); virBufferTrim(&buf, "\n", -1); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index ee9195b..382d73f 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -499,7 +499,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, for (j = 0; j < rule->nVarAccess; j++) { if (!virNWFilterVarAccessIsAvailable(rule->varAccess[j], vars)) { - const char *varAccess; + char *varAccess; virBuffer buf = VIR_BUFFER_INITIALIZER; virNWFilterVarAccessPrint(rule->varAccess[j], &buf); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f8fccea..754d95a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6050,7 +6050,8 @@ static char *qemuBuildTPMBackendStr(const virDomainDefPtr def, const virDomainTPMDefPtr tpm = def->tpm; virBuffer buf = VIR_BUFFER_INITIALIZER; const char *type = virDomainTPMBackendTypeToString(tpm->type); - const char *cancel_path, *tpmdev; + char *cancel_path; + const char *tpmdev; virBufferAsprintf(&buf, "%s,id=tpm-%s", type, tpm->info.alias); @@ -7667,7 +7668,7 @@ qemuBuildCommandLine(virConnectPtr conn, } if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_RTC)) { - const char *rtcopt; + char *rtcopt; virCommandAddArg(cmd, "-rtc"); if (!(rtcopt = qemuBuildClockArgStr(&def->clock))) goto error; @@ -9529,8 +9530,8 @@ qemuBuildChrDeviceStr(char **deviceStr, * on space */ static int qemuStringToArgvEnv(const char *args, - const char ***retenv, - const char ***retargv) + char ***retenv, + char ***retargv) { char **arglist = NULL; int argcount = 0; @@ -9539,8 +9540,8 @@ static int qemuStringToArgvEnv(const char *args, size_t i; const char *curr = args; const char *start; - const char **progenv = NULL; - const char **progargv = NULL; + char **progenv = NULL; + char **progargv = NULL; /* Iterate over string, splitting on sequences of ' ' */ while (curr && *curr != '\0') { @@ -11738,15 +11739,17 @@ virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps, virDomainChrSourceDefPtr *monConfig, bool *monJSON) { - const char **progenv = NULL; - const char **progargv = NULL; + char **progenv = NULL; + char **progargv = NULL; virDomainDefPtr def = NULL; size_t i; if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0) goto cleanup; - def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv, + def = qemuParseCommandLine(qemuCaps, xmlopt, + (const char **)progenv, + (const char **)progargv, pidfile, monConfig, monJSON); cleanup: @@ -11764,7 +11767,7 @@ cleanup: static int qemuParseProcFileStrings(int pid_value, const char *name, - const char ***list) + char ***list) { char *path = NULL; int ret = -1; @@ -11800,7 +11803,7 @@ static int qemuParseProcFileStrings(int pid_value, str[nstr-1] = NULL; ret = nstr-1; - *list = (const char **) str; + *list = str; cleanup: if (ret < 0) { @@ -11821,8 +11824,8 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, bool *monJSON) { virDomainDefPtr def = NULL; - const char **progargv = NULL; - const char **progenv = NULL; + char **progargv = NULL; + char **progenv = NULL; char *exepath = NULL; char *emulator; size_t i; @@ -11834,7 +11837,9 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, qemuParseProcFileStrings(pid, "environ", &progenv) < 0) goto cleanup; - if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, progenv, progargv, + if (!(def = qemuParseCommandLine(qemuCaps, xmlopt, + (const char **)progenv, + (const char **)progargv, pidfile, monConfig, monJSON))) goto cleanup; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7f4d17d..b71fa4e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1355,7 +1355,7 @@ qemuDomainDefCopy(virQEMUDriverPtr driver, virBuffer buf = VIR_BUFFER_INITIALIZER; virDomainDefPtr ret = NULL; virCapsPtr caps = NULL; - const char *xml = NULL; + char *xml = NULL; if (qemuDomainDefFormatBuf(driver, src, flags, &buf) < 0) goto cleanup; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ed29373..fa70e74 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14646,7 +14646,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, virDomainDefPtr persistentDef = NULL; virDomainBlockIoTuneInfo info; virDomainBlockIoTuneInfo *oldinfo; - const char *device = NULL; + char *device = NULL; int ret = -1; size_t i; int idx = -1; @@ -14824,7 +14824,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, qemuDomainObjPrivatePtr priv; virDomainDefPtr persistentDef = NULL; virDomainBlockIoTuneInfo reply; - const char *device = NULL; + char *device = NULL; int ret = -1; size_t i; virCapsPtr caps = NULL; diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 816c54e..f544d69 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -268,8 +268,9 @@ virNetSSHKbIntCb(const char *name ATTRIBUTE_UNUSED, cleanup: if (askcred) { for (i = 0; i < num_prompts; i++) { + char *prompt = (char *)askcred[i].prompt; VIR_FREE(askcred[i].result); - VIR_FREE(askcred[i].prompt); + VIR_FREE(prompt); } } @@ -291,6 +292,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) int ret; const char *key; const char *keyhash; + char *keyhashstr; + char *tmp; int keyType; size_t keyLength; char *errmsg; @@ -364,7 +367,7 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) * Sadly, there's no constant to describe the hash length, so * we have to use a *MAGIC* constant. */ for (i = 0; i < 16; i++) - virBufferAsprintf(&buff, "%02hhX:", keyhash[i]); + virBufferAsprintf(&buff, "%02hhX:", keyhash[i]); virBufferTrim(&buff, ":", 1); if (virBufferError(&buff) != 0) { @@ -372,16 +375,16 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) return -1; } - keyhash = virBufferContentAndReset(&buff); + keyhashstr = virBufferContentAndReset(&buff); askKey.type = VIR_CRED_ECHOPROMPT; if (virAsprintf((char **)&askKey.prompt, _("Accept SSH host key with hash '%s' for " "host '%s:%d' (%s/%s)?"), - keyhash, + keyhashstr, sess->hostname, sess->port, "y", "n") < 0) { - VIR_FREE(keyhash); + VIR_FREE(keyhashstr); return -1; } @@ -389,23 +392,25 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) virReportError(VIR_ERR_SSH, "%s", _("failed to retrieve decision to accept " "host key")); - VIR_FREE(askKey.prompt); - VIR_FREE(keyhash); + tmp = (char*)askKey.prompt; + VIR_FREE(tmp); + VIR_FREE(keyhashstr); return -1; } - VIR_FREE(askKey.prompt); + tmp = (char*)askKey.prompt; + VIR_FREE(tmp); if (!askKey.result || STRCASENEQ(askKey.result, "y")) { virReportError(VIR_ERR_SSH, _("SSH host key for '%s' (%s) was not accepted"), - sess->hostname, keyhash); - VIR_FREE(keyhash); + sess->hostname, keyhashstr); + VIR_FREE(keyhashstr); VIR_FREE(askKey.result); return -1; } - VIR_FREE(keyhash); + VIR_FREE(keyhashstr); VIR_FREE(askKey.result); } @@ -590,6 +595,7 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess, size_t i; char *errmsg; int ret; + char *tmp; /* try open the key with no password */ if ((ret = libssh2_userauth_publickey_fromfile(sess->session, @@ -644,11 +650,13 @@ virNetSSHAuthenticatePrivkey(virNetSSHSessionPtr sess, virReportError(VIR_ERR_SSH, "%s", _("failed to retrieve private key passphrase: " "callback has failed")); - VIR_FREE(retr_passphrase.prompt); + tmp = (char *)retr_passphrase.prompt; + VIR_FREE(tmp); return -1; } - VIR_FREE(retr_passphrase.prompt); + tmp = (char *)retr_passphrase.prompt; + VIR_FREE(tmp); ret = libssh2_userauth_publickey_fromfile(sess->session, priv->username, diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 4ebe11b..ed893f0 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -931,7 +931,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, unsigned int flags) { int ret = -1; - const char *create_tool; + char *create_tool; int imgformat; virCommandPtr cmd; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 323be9e..6c39284 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1450,7 +1450,7 @@ storageVolLookupByPath(virConnectPtr conn, virStoragePoolObjLock(driver->pools.objs[i]); if (virStoragePoolObjIsActive(driver->pools.objs[i])) { virStorageVolDefPtr vol; - const char *stable_path; + char *stable_path; stable_path = virStorageBackendStablePath(driver->pools.objs[i], cleanpath, diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 00ff69a..95331a6 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -405,6 +405,7 @@ virExec(virCommandPtr cmd) int childout = -1; int childerr = -1; int tmpfd; + char *binarystr = NULL; const char *binary = NULL; int forkRet, ret; struct sigaction waxon, waxoff; @@ -412,7 +413,7 @@ virExec(virCommandPtr cmd) int ngroups; if (cmd->args[0][0] != '/') { - if (!(binary = virFindFileInPath(cmd->args[0]))) { + if (!(binary = binarystr = virFindFileInPath(cmd->args[0]))) { virReportSystemError(ENOENT, _("Cannot find '%s' in path"), cmd->args[0]); @@ -506,8 +507,7 @@ virExec(virCommandPtr cmd) cmd->pid = pid; - if (binary != cmd->args[0]) - VIR_FREE(binary); + VIR_FREE(binarystr); VIR_FREE(groups); return 0; @@ -713,8 +713,7 @@ virExec(virCommandPtr cmd) should never jump here on error */ VIR_FREE(groups); - if (binary != cmd->args[0]) - VIR_FREE(binary); + VIR_FREE(binarystr); /* NB we don't virReportError() on any failures here because the code which jumped here already raised diff --git a/src/util/virlog.c b/src/util/virlog.c index 047a131..7ee5117 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -94,7 +94,7 @@ static regex_t *virLogRegex = NULL; * based on a matching pattern (currently a substring) */ struct _virLogFilter { - const char *match; + char *match; virLogPriority priority; unsigned int flags; }; @@ -115,7 +115,7 @@ struct _virLogOutput { virLogCloseFunc c; virLogPriority priority; virLogDestination dest; - const char *name; + char *name; }; typedef struct _virLogOutput virLogOutput; typedef virLogOutput *virLogOutputPtr; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 568d61d..ad15912 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2346,8 +2346,8 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom; const char *iface; const char *state; - const char *value; - const char *desc; + char *value; + char *desc; virMacAddr macaddr; const char *element; const char *attr; @@ -6167,7 +6167,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) bool ret = false; char *buffer; char *result = NULL; - const char **list = NULL; + char **list = NULL; unsigned int flags = 0; int count = 0; @@ -6224,7 +6224,8 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) list[i] = vshStrdup(ctl, (const char *)xmlBufferContent(xml_buf)); } - result = virConnectBaselineCPU(ctl->conn, list, count, flags); + result = virConnectBaselineCPU(ctl->conn, + (const char **)list, count, flags); if (result) { vshPrint(ctl, "%s", result); @@ -6379,7 +6380,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) params[pos].value.ul / 1000000000, params[pos].value.ul % 1000000000); } else { - const char *s = vshGetTypedParamValue(ctl, ¶ms[pos]); + char *s = vshGetTypedParamValue(ctl, ¶ms[pos]); vshPrint(ctl, _("%s\n"), s); VIR_FREE(s); } @@ -9855,8 +9856,8 @@ vshPrepareDiskXML(xmlNodePtr disk_node, { xmlNodePtr cur = NULL; xmlBufferPtr xml_buf = NULL; - const char *disk_type = NULL; - const char *device_type = NULL; + char *disk_type = NULL; + char *device_type = NULL; xmlNodePtr new_node = NULL; char *ret = NULL; @@ -10192,9 +10193,9 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd) virDomainPtr dom = NULL; const char *source = NULL; const char *path = NULL; - const char *doc = NULL; + char *doc = NULL; xmlNodePtr disk_node = NULL; - const char *disk_xml = NULL; + char *disk_xml = NULL; bool ret = false; int prepare_type = 0; const char *action = NULL; -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list