Stop free'ing 'const char *' strings

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@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-09-03 12:36:22 +01:00
parent 41b5505679
commit bbcdd9b5dc
14 changed files with 66 additions and 56 deletions

View File

@ -6777,9 +6777,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,
@ -8193,7 +8193,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");
@ -8227,7 +8227,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) {
@ -8248,7 +8248,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) {
@ -8269,7 +8269,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) {
@ -8290,7 +8290,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) {
@ -8311,7 +8311,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) {
@ -8331,7 +8331,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) {
@ -8351,7 +8351,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) {
@ -8543,9 +8543,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;
@ -15220,7 +15220,7 @@ virDomainChrDefFormat(virBufferPtr buf,
return -1;
}
const char *addr = virSocketAddrFormat(def->target.addr);
char *addr = virSocketAddrFormat(def->target.addr);
if (addr == NULL)
return -1;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -6147,7 +6147,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);
@ -7772,7 +7773,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;

View File

@ -1383,7 +1383,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;

View File

@ -14658,7 +14658,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;
@ -14836,7 +14836,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;

View File

@ -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;
@ -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,

View File

@ -931,7 +931,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
unsigned int flags)
{
int ret = -1;
const char *create_tool;
char *create_tool;
int imgformat;
virCommandPtr cmd;

View File

@ -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,

View File

@ -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

View File

@ -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;

View File

@ -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;
@ -6186,7 +6186,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;
@ -6243,7 +6243,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);
@ -6398,7 +6399,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
params[pos].value.ul / 1000000000,
params[pos].value.ul % 1000000000);
} else {
const char *s = vshGetTypedParamValue(ctl, &params[pos]);
char *s = vshGetTypedParamValue(ctl, &params[pos]);
vshPrint(ctl, _("%s\n"), s);
VIR_FREE(s);
}
@ -9874,8 +9875,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;
@ -10211,9 +10212,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;