qemu_domain.c: use g_autofree when possible

Use g_autofree to remove VIR_FREE() calls used for cleanups.
Labels that became deprecated will be removed in a later
patch.

In qemuDomainSetupDisk(), the 'dst' variable is not used at
all and could be removed.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Daniel Henrique Barboza 2020-01-09 15:33:44 -03:00 committed by Michal Privoznik
parent 749ec34a56
commit ae9f630e50

View File

@ -877,7 +877,7 @@ int
qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver, qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
char *path; g_autofree char *path = NULL;
int fd = -1; int fd = -1;
int ret = -1; int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
@ -908,7 +908,6 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
cleanup: cleanup:
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
return ret; return ret;
} }
@ -944,7 +943,7 @@ qemuDomainMasterKeyFree(qemuDomainObjPrivatePtr priv)
int int
qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv) qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv)
{ {
char *path; g_autofree char *path = NULL;
int fd = -1; int fd = -1;
uint8_t *masterKey = NULL; uint8_t *masterKey = NULL;
ssize_t masterKeyLen = 0; ssize_t masterKeyLen = 0;
@ -990,7 +989,6 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv)
priv->masterKeyLen = masterKeyLen; priv->masterKeyLen = masterKeyLen;
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
return 0; return 0;
@ -1000,7 +998,6 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv)
VIR_FREE(masterKey); VIR_FREE(masterKey);
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
return -1; return -1;
} }
@ -1015,7 +1012,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivatePtr priv)
void void
qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv) qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv)
{ {
char *path = NULL; g_autofree char *path = NULL;
if (!priv->masterKey) if (!priv->masterKey)
return; return;
@ -1026,8 +1023,6 @@ qemuDomainMasterKeyRemove(qemuDomainObjPrivatePtr priv)
/* Delete the master key file */ /* Delete the master key file */
path = qemuDomainGetMasterKeyFilePath(priv->libDir); path = qemuDomainGetMasterKeyFilePath(priv->libDir);
unlink(path); unlink(path);
VIR_FREE(path);
} }
@ -1909,7 +1904,7 @@ qemuDomainSecretChardevPrepare(virQEMUDriverConfigPtr cfg,
const char *chrAlias, const char *chrAlias,
virDomainChrSourceDefPtr dev) virDomainChrSourceDefPtr dev)
{ {
char *charAlias = NULL; g_autofree char *charAlias = NULL;
if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP) if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP)
return 0; return 0;
@ -1925,7 +1920,6 @@ qemuDomainSecretChardevPrepare(virQEMUDriverConfigPtr cfg,
chrSourcePriv->secinfo = chrSourcePriv->secinfo =
qemuDomainSecretInfoTLSNew(priv, charAlias, qemuDomainSecretInfoTLSNew(priv, charAlias,
cfg->chardevTLSx509secretUUID); cfg->chardevTLSx509secretUUID);
VIR_FREE(charAlias);
if (!chrSourcePriv->secinfo) if (!chrSourcePriv->secinfo)
return -1; return -1;
@ -2143,7 +2137,7 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char *domname = virDomainDefGetShortName(vm->def); g_autofree char *domname = virDomainDefGetShortName(vm->def);
int ret = -1; int ret = -1;
if (!domname) if (!domname)
@ -2159,7 +2153,6 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(cfg); virObjectUnref(cfg);
VIR_FREE(domname);
return ret; return ret;
} }
@ -2340,8 +2333,8 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
qemuDomainStorageSourcePrivatePtr priv; qemuDomainStorageSourcePrivatePtr priv;
char *authalias = NULL; g_autofree char *authalias = NULL;
char *encalias = NULL; g_autofree char *encalias = NULL;
int ret = -1; int ret = -1;
src->nodestorage = virXPathString("string(./nodenames/nodename[@type='storage']/@name)", ctxt); src->nodestorage = virXPathString("string(./nodenames/nodename[@type='storage']/@name)", ctxt);
@ -2374,8 +2367,6 @@ qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(authalias);
VIR_FREE(encalias);
return ret; return ret;
} }
@ -2497,8 +2488,8 @@ static int
qemuDomainObjPrivateXMLFormatAutomaticPlacement(virBufferPtr buf, qemuDomainObjPrivateXMLFormatAutomaticPlacement(virBufferPtr buf,
qemuDomainObjPrivatePtr priv) qemuDomainObjPrivatePtr priv)
{ {
char *nodeset = NULL; g_autofree char *nodeset = NULL;
char *cpuset = NULL; g_autofree char *cpuset = NULL;
int ret = -1; int ret = -1;
if (!priv->autoNodeset && !priv->autoCpuset) if (!priv->autoNodeset && !priv->autoCpuset)
@ -2520,8 +2511,6 @@ qemuDomainObjPrivateXMLFormatAutomaticPlacement(virBufferPtr buf,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(nodeset);
VIR_FREE(cpuset);
return ret; return ret;
} }
@ -3022,8 +3011,8 @@ qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node,
virDomainDefPtr def) virDomainDefPtr def)
{ {
virDomainVcpuDefPtr vcpu; virDomainVcpuDefPtr vcpu;
char *idstr; g_autofree char *idstr = NULL;
char *pidstr; g_autofree char *pidstr = NULL;
unsigned int tmp; unsigned int tmp;
int ret = -1; int ret = -1;
@ -3052,8 +3041,6 @@ qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(idstr);
VIR_FREE(pidstr);
return ret; return ret;
} }
@ -3064,8 +3051,8 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt,
virQEMUDriverPtr driver) virQEMUDriverPtr driver)
{ {
g_autoptr(virCapsHostNUMA) caps = NULL; g_autoptr(virCapsHostNUMA) caps = NULL;
char *nodeset; g_autofree char *nodeset = NULL;
char *cpuset; g_autofree char *cpuset = NULL;
int nodesetSize = 0; int nodesetSize = 0;
size_t i; size_t i;
int ret = -1; int ret = -1;
@ -3106,8 +3093,6 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(nodeset);
VIR_FREE(cpuset);
return ret; return ret;
} }
@ -3428,7 +3413,7 @@ qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
{ {
int ret = -1; int ret = -1;
int val; int val;
char *valStr; g_autofree char *valStr = NULL;
if ((valStr = virXPathString("string(./allowReboot/@value)", ctxt))) { if ((valStr = virXPathString("string(./allowReboot/@value)", ctxt))) {
if ((val = virTristateBoolTypeFromString(valStr)) < 0) { if ((val = virTristateBoolTypeFromString(valStr)) < 0) {
@ -3442,7 +3427,6 @@ qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(valStr);
return ret; return ret;
} }
@ -3507,8 +3491,7 @@ qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
qemuDomainObjPrivatePtr priv, qemuDomainObjPrivatePtr priv,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
char *dst = NULL;
size_t i; size_t i;
int n; int n;
int ret = -1; int ret = -1;
@ -3524,6 +3507,7 @@ qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
} }
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
g_autofree char *dst = NULL;
if ((dst = virXMLPropString(nodes[i], "dev")) && if ((dst = virXMLPropString(nodes[i], "dev")) &&
(disk = virDomainDiskByTarget(vm->def, dst))) { (disk = virDomainDiskByTarget(vm->def, dst))) {
@ -3534,16 +3518,12 @@ qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm,
priv->driver->xmlopt) < 0) priv->driver->xmlopt) < 0)
goto cleanup; goto cleanup;
} }
VIR_FREE(dst);
} }
} }
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(nodes);
VIR_FREE(dst);
return ret; return ret;
} }
@ -3554,7 +3534,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *tmp = NULL; g_autofree char *tmp = NULL;
int ret = -1; int ret = -1;
if (!(ctxt->node = virXPathNode("./job[1]", ctxt))) { if (!(ctxt->node = virXPathNode("./job[1]", ctxt))) {
@ -3610,7 +3590,6 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(tmp);
return ret; return ret;
} }
@ -3662,10 +3641,10 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverPtr driver = config->priv; virQEMUDriverPtr driver = config->priv;
char *monitorpath; char *monitorpath;
char *tmp = NULL; g_autofree char *tmp = NULL;
int n; int n;
size_t i; size_t i;
xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
xmlNodePtr node = NULL; xmlNodePtr node = NULL;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
@ -3752,16 +3731,14 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
goto error; goto error;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
char *str = virXMLPropString(nodes[i], "name"); g_autofree char *str = virXMLPropString(nodes[i], "name");
if (str) { if (str) {
int flag = virQEMUCapsTypeFromString(str); int flag = virQEMUCapsTypeFromString(str);
if (flag < 0) { if (flag < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown qemu capabilities flag %s"), str); _("Unknown qemu capabilities flag %s"), str);
VIR_FREE(str);
goto error; goto error;
} }
VIR_FREE(str);
virQEMUCapsSet(qemuCaps, flag); virQEMUCapsSet(qemuCaps, flag);
} }
} }
@ -3867,8 +3844,6 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
return 0; return 0;
error: error:
VIR_FREE(nodes);
VIR_FREE(tmp);
virBitmapFree(priv->namespaces); virBitmapFree(priv->namespaces);
priv->namespaces = NULL; priv->namespaces = NULL;
virObjectUnref(priv->monConfig); virObjectUnref(priv->monConfig);
@ -8599,7 +8574,7 @@ qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr,
{ {
virQEMUDriverConfigPtr cfg; virQEMUDriverConfigPtr cfg;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *regexp = NULL; g_autofree char *regexp = NULL;
int ret = -1; int ret = -1;
if (chr->deviceType != VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL || if (chr->deviceType != VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL ||
@ -8621,7 +8596,6 @@ qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr,
VIR_FREE(chr->source->data.nix.path); VIR_FREE(chr->source->data.nix.path);
ret = 0; ret = 0;
VIR_FREE(regexp);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -8917,8 +8891,8 @@ qemuDomainDeviceDiskDefPostParseRestoreSecAlias(virDomainDiskDefPtr disk,
qemuDomainStorageSourcePrivatePtr priv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src); qemuDomainStorageSourcePrivatePtr priv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
bool restoreAuthSecret = false; bool restoreAuthSecret = false;
bool restoreEncSecret = false; bool restoreEncSecret = false;
char *authalias = NULL; g_autofree char *authalias = NULL;
char *encalias = NULL; g_autofree char *encalias = NULL;
int ret = -1; int ret = -1;
if (!(parseFlags & VIR_DOMAIN_DEF_PARSE_STATUS) || if (!(parseFlags & VIR_DOMAIN_DEF_PARSE_STATUS) ||
@ -8976,8 +8950,6 @@ qemuDomainDeviceDiskDefPostParseRestoreSecAlias(virDomainDiskDefPtr disk,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(authalias);
VIR_FREE(encalias);
return ret; return ret;
} }
@ -10042,14 +10014,13 @@ qemuDomainDefCopy(virQEMUDriverPtr driver,
unsigned int flags) unsigned int flags)
{ {
virDomainDefPtr ret = NULL; virDomainDefPtr ret = NULL;
char *xml; g_autofree char *xml = NULL;
if (!(xml = qemuDomainDefFormatXML(driver, qemuCaps, src, flags))) if (!(xml = qemuDomainDefFormatXML(driver, qemuCaps, src, flags)))
return NULL; return NULL;
ret = qemuDomainDefFromXML(driver, qemuCaps, xml); ret = qemuDomainDefFromXML(driver, qemuCaps, xml);
VIR_FREE(xml);
return ret; return ret;
} }
@ -10348,7 +10319,7 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt)
{ {
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
char *timestamp = NULL; g_autofree char *timestamp = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
int rc; int rc;
@ -10389,7 +10360,6 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
virResetLastError(); virResetLastError();
cleanup: cleanup:
VIR_FREE(timestamp);
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
} }
@ -10586,7 +10556,7 @@ int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list argptr; va_list argptr;
char *message = NULL; g_autofree char *message = NULL;
int ret = -1; int ret = -1;
va_start(argptr, fmt); va_start(argptr, fmt);
@ -10608,7 +10578,6 @@ int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
cleanup: cleanup:
va_end(argptr); va_end(argptr);
VIR_FREE(message);
return ret; return ret;
} }
@ -10677,9 +10646,9 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virLogManagerPtr manager = NULL; virLogManagerPtr manager = NULL;
va_list ap; va_list ap;
char *path = NULL; g_autofree char *path = NULL;
int writefd = -1; int writefd = -1;
char *message = NULL; g_autofree char *message = NULL;
int ret = -1; int ret = -1;
va_start(ap, fmt); va_start(ap, fmt);
@ -10713,11 +10682,9 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
cleanup: cleanup:
va_end(ap); va_end(ap);
VIR_FREE(message);
VIR_FORCE_CLOSE(writefd); VIR_FORCE_CLOSE(writefd);
virLogManagerFree(manager); virLogManagerFree(manager);
virObjectUnref(cfg); virObjectUnref(cfg);
VIR_FREE(path);
return ret; return ret;
} }
@ -10765,10 +10732,10 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
const char *snapshotDir) const char *snapshotDir)
{ {
char *newxml = NULL; g_autofree char *newxml = NULL;
int ret = -1; int ret = -1;
char *snapDir = NULL; g_autofree char *snapDir = NULL;
char *snapFile = NULL; g_autofree char *snapFile = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
unsigned int flags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE | unsigned int flags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL; VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL;
@ -10793,9 +10760,6 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml); ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml);
cleanup: cleanup:
VIR_FREE(snapFile);
VIR_FREE(snapDir);
VIR_FREE(newxml);
return ret; return ret;
} }
@ -10900,7 +10864,7 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
bool update_parent, bool update_parent,
bool metadata_only) bool metadata_only)
{ {
char *snapFile = NULL; g_autofree char *snapFile = NULL;
int ret = -1; int ret = -1;
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
virDomainMomentObjPtr parentsnap = NULL; virDomainMomentObjPtr parentsnap = NULL;
@ -10954,7 +10918,6 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(snapFile);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -12282,7 +12245,7 @@ qemuDomainCheckABIStability(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr migratableSrc = NULL; virDomainDefPtr migratableSrc = NULL;
virDomainDefPtr migratableDst = NULL; virDomainDefPtr migratableDst = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
bool ret = false; bool ret = false;
if (!(xml = qemuDomainFormatXML(driver, vm, COPY_FLAGS)) || if (!(xml = qemuDomainFormatXML(driver, vm, COPY_FLAGS)) ||
@ -12295,7 +12258,6 @@ qemuDomainCheckABIStability(virQEMUDriverPtr driver,
dst, migratableDst); dst, migratableDst);
cleanup: cleanup:
VIR_FREE(xml);
virDomainDefFree(migratableSrc); virDomainDefFree(migratableSrc);
virDomainDefFree(migratableDst); virDomainDefFree(migratableDst);
return ret; return ret;
@ -14128,7 +14090,7 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg,
char *path = NULL; char *path = NULL;
char *tmp; char *tmp;
const char *suffix = mountpoint + strlen(QEMU_DEVPREFIX); const char *suffix = mountpoint + strlen(QEMU_DEVPREFIX);
char *domname = virDomainDefGetShortName(vm->def); g_autofree char *domname = virDomainDefGetShortName(vm->def);
size_t off; size_t off;
if (!domname) if (!domname)
@ -14153,7 +14115,6 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg,
tmp++; tmp++;
} }
VIR_FREE(domname);
return path; return path;
} }
@ -14255,8 +14216,8 @@ qemuDomainCreateDeviceRecursive(const char *device,
bool allow_noent, bool allow_noent,
unsigned int ttl) unsigned int ttl)
{ {
char *devicePath = NULL; g_autofree char *devicePath = NULL;
char *target = NULL; g_autofree char *target = NULL;
GStatBuf sb; GStatBuf sb;
int ret = -1; int ret = -1;
bool isLink = false; bool isLink = false;
@ -14366,15 +14327,13 @@ qemuDomainCreateDeviceRecursive(const char *device,
* /dev/stdout -> /proc/self/fd/1 (no change needed) * /dev/stdout -> /proc/self/fd/1 (no change needed)
*/ */
if (!g_path_is_absolute(target)) { if (!g_path_is_absolute(target)) {
char *c = NULL, *tmp = NULL, *devTmp = NULL; g_autofree char *devTmp = g_strdup(device);
char *c = NULL, *tmp = NULL;
devTmp = g_strdup(device);
if ((c = strrchr(devTmp, '/'))) if ((c = strrchr(devTmp, '/')))
*(c + 1) = '\0'; *(c + 1) = '\0';
tmp = g_strdup_printf("%s%s", devTmp, target); tmp = g_strdup_printf("%s%s", devTmp, target);
VIR_FREE(devTmp);
VIR_FREE(target); VIR_FREE(target);
target = g_steal_pointer(&tmp); target = g_steal_pointer(&tmp);
} }
@ -14469,8 +14428,6 @@ qemuDomainCreateDeviceRecursive(const char *device,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(target);
VIR_FREE(devicePath);
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
freecon(tcon); freecon(tcon);
#endif #endif
@ -14516,8 +14473,8 @@ qemuDomainSetupDev(virQEMUDriverConfigPtr cfg,
virDomainObjPtr vm, virDomainObjPtr vm,
const struct qemuDomainCreateDeviceData *data) const struct qemuDomainCreateDeviceData *data)
{ {
char *mount_options = NULL; g_autofree char *mount_options = NULL;
char *opts = NULL; g_autofree char *opts = NULL;
int ret = -1; int ret = -1;
VIR_DEBUG("Setting up /dev/ for domain %s", vm->def->name); VIR_DEBUG("Setting up /dev/ for domain %s", vm->def->name);
@ -14541,8 +14498,6 @@ qemuDomainSetupDev(virQEMUDriverConfigPtr cfg,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(opts);
VIR_FREE(mount_options);
return ret; return ret;
} }
@ -14553,7 +14508,6 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
const struct qemuDomainCreateDeviceData *data) const struct qemuDomainCreateDeviceData *data)
{ {
virStorageSourcePtr next; virStorageSourcePtr next;
char *dst = NULL;
bool hasNVMe = false; bool hasNVMe = false;
int ret = -1; int ret = -1;
@ -14590,7 +14544,6 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(dst);
return ret; return ret;
} }
@ -15293,7 +15246,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
virQEMUDriverConfigPtr cfg = NULL; virQEMUDriverConfigPtr cfg = NULL;
struct qemuDomainAttachDeviceMknodData data; struct qemuDomainAttachDeviceMknodData data;
int ret = -1; int ret = -1;
char *target = NULL; g_autofree char *target = NULL;
bool isLink; bool isLink;
bool isReg; bool isReg;
bool isDir; bool isDir;
@ -15340,15 +15293,13 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
} }
if (!g_path_is_absolute(target)) { if (!g_path_is_absolute(target)) {
char *c = NULL, *tmp = NULL, *fileTmp = NULL; g_autofree char *fileTmp = g_strdup(file);
char *c = NULL, *tmp = NULL;
fileTmp = g_strdup(file);
if ((c = strrchr(fileTmp, '/'))) if ((c = strrchr(fileTmp, '/')))
*(c + 1) = '\0'; *(c + 1) = '\0';
tmp = g_strdup_printf("%s%s", fileTmp, target); tmp = g_strdup_printf("%s%s", fileTmp, target);
VIR_FREE(fileTmp);
VIR_FREE(target); VIR_FREE(target);
target = g_steal_pointer(&tmp); target = g_steal_pointer(&tmp);
} }
@ -15415,7 +15366,6 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
virFileFreeACLs(&data.acl); virFileFreeACLs(&data.acl);
if (isReg && target) if (isReg && target)
umount(target); umount(target);
VIR_FREE(target);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -15951,7 +15901,7 @@ qemuDomainGetStorageSourceByDevstr(const char *devstr,
{ {
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
virStorageSourcePtr src = NULL; virStorageSourcePtr src = NULL;
char *target = NULL; g_autofree char *target = NULL;
unsigned int idx; unsigned int idx;
size_t i; size_t i;
@ -15980,7 +15930,6 @@ qemuDomainGetStorageSourceByDevstr(const char *devstr,
src = virStorageFileChainLookup(disk->src, NULL, NULL, idx, NULL); src = virStorageFileChainLookup(disk->src, NULL, NULL, idx, NULL);
cleanup: cleanup:
VIR_FREE(target);
return src; return src;
} }