qemu_process.c: use g_autofree

Change all feasible strings and scalar pointers to use g_autofree.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2019-12-20 18:16:28 -03:00 committed by Cole Robinson
parent 290c1ea733
commit 982ea95142

View File

@ -105,7 +105,7 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
char ebuf[1024]; char ebuf[1024];
char *file = NULL; g_autofree char *file = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@ -114,7 +114,6 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR) if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s", VIR_WARN("Failed to remove domain XML for %s: %s",
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf))); vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
VIR_FREE(file);
if (priv->pidfile && if (priv->pidfile &&
unlink(priv->pidfile) < 0 && unlink(priv->pidfile) < 0 &&
@ -1501,7 +1500,6 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED,
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
virStorageSourcePtr src; virStorageSourcePtr src;
unsigned int idx; unsigned int idx;
char *dev = NULL;
const char *path = NULL; const char *path = NULL;
virObjectLock(vm); virObjectLock(vm);
@ -1511,14 +1509,13 @@ qemuProcessHandleBlockThreshold(qemuMonitorPtr mon G_GNUC_UNUSED,
nodename, vm, vm->def->name, threshold, excess); nodename, vm, vm->def->name, threshold, excess);
if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) { if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) {
g_autofree char *dev = NULL;
if (virStorageSourceIsLocalStorage(src)) if (virStorageSourceIsLocalStorage(src))
path = src->path; path = src->path;
if ((dev = qemuDomainDiskBackingStoreGetName(disk, src, idx))) { if ((dev = qemuDomainDiskBackingStoreGetName(disk, src, idx)))
event = virDomainEventBlockThresholdNewFromObj(vm, dev, path, event = virDomainEventBlockThresholdNewFromObj(vm, dev, path,
threshold, excess); threshold, excess);
VIR_FREE(dev);
}
} }
virObjectUnlock(vm); virObjectUnlock(vm);
@ -2052,7 +2049,7 @@ static int
qemuProcessReportLogError(qemuDomainLogContextPtr logCtxt, qemuProcessReportLogError(qemuDomainLogContextPtr logCtxt,
const char *msgprefix) const char *msgprefix)
{ {
char *logmsg = NULL; g_autofree char *logmsg = NULL;
size_t max; size_t max;
max = VIR_ERROR_MAX_LENGTH - 1; max = VIR_ERROR_MAX_LENGTH - 1;
@ -2069,7 +2066,6 @@ qemuProcessReportLogError(qemuDomainLogContextPtr logCtxt,
else else
virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: %s"), msgprefix, logmsg); virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: %s"), msgprefix, logmsg);
VIR_FREE(logmsg);
return 0; return 0;
} }
@ -2089,16 +2085,15 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
int count, int count,
virHashTablePtr info) virHashTablePtr info)
{ {
char *id = NULL;
size_t i; size_t i;
int ret = -1; int ret = -1;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
g_autofree char *id = NULL;
virDomainChrDefPtr chr = devices[i]; virDomainChrDefPtr chr = devices[i];
if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) { if (chr->source->type == VIR_DOMAIN_CHR_TYPE_PTY) {
qemuMonitorChardevInfoPtr entry; qemuMonitorChardevInfoPtr entry;
VIR_FREE(id);
id = g_strdup_printf("char%s", chr->info.alias); id = g_strdup_printf("char%s", chr->info.alias);
entry = virHashLookup(info, id); entry = virHashLookup(info, id);
@ -2118,14 +2113,13 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
} }
} }
VIR_FREE(chr->source->data.file.path); g_free(chr->source->data.file.path);
chr->source->data.file.path = g_strdup(entry->ptyPath); chr->source->data.file.path = g_strdup(entry->ptyPath);
} }
} }
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(id);
return ret; return ret;
} }
@ -2178,7 +2172,7 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
int agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL; int agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL;
qemuMonitorChardevInfoPtr entry; qemuMonitorChardevInfoPtr entry;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
char *id = NULL; g_autofree char *id = NULL;
if (booted) if (booted)
agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED; agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED;
@ -2204,8 +2198,6 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
chr->state = entry->state; chr->state = entry->state;
} }
} }
VIR_FREE(id);
} }
@ -2622,7 +2614,7 @@ qemuProcessSetupPid(virDomainObjPtr vm,
virBitmapPtr use_cpumask = NULL; virBitmapPtr use_cpumask = NULL;
virBitmapPtr afinity_cpumask = NULL; virBitmapPtr afinity_cpumask = NULL;
g_autoptr(virBitmap) hostcpumap = NULL; g_autoptr(virBitmap) hostcpumap = NULL;
char *mem_mask = NULL; g_autofree char *mem_mask = NULL;
int ret = -1; int ret = -1;
if ((period || quota) && if ((period || quota) &&
@ -2702,7 +2694,6 @@ qemuProcessSetupPid(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(mem_mask);
if (cgroup) { if (cgroup) {
if (ret < 0) if (ret < 0)
virCgroupRemove(cgroup); virCgroupRemove(cgroup);
@ -2781,7 +2772,7 @@ qemuProcessKillManagedPRDaemon(virDomainObjPtr vm)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virErrorPtr orig_err; virErrorPtr orig_err;
char *pidfile; g_autofree char *pidfile = NULL;
if (!(pidfile = qemuProcessBuildPRHelperPidfilePath(vm))) { if (!(pidfile = qemuProcessBuildPRHelperPidfilePath(vm))) {
VIR_WARN("Unable to construct pr-helper pidfile path"); VIR_WARN("Unable to construct pr-helper pidfile path");
@ -2802,8 +2793,6 @@ qemuProcessKillManagedPRDaemon(virDomainObjPtr vm)
} }
} }
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
VIR_FREE(pidfile);
} }
@ -2812,7 +2801,7 @@ qemuProcessStartPRDaemonHook(void *opaque)
{ {
virDomainObjPtr vm = opaque; virDomainObjPtr vm = opaque;
size_t i, nfds = 0; size_t i, nfds = 0;
int *fds = NULL; g_autofree int *fds = NULL;
int ret = -1; int ret = -1;
if (qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) { if (qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) {
@ -2828,7 +2817,6 @@ qemuProcessStartPRDaemonHook(void *opaque)
cleanup: cleanup:
for (i = 0; i < nfds; i++) for (i = 0; i < nfds; i++)
VIR_FORCE_CLOSE(fds[i]); VIR_FORCE_CLOSE(fds[i]);
VIR_FREE(fds);
return ret; return ret;
} }
@ -2840,9 +2828,9 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
virQEMUDriverPtr driver = priv->driver; virQEMUDriverPtr driver = priv->driver;
virQEMUDriverConfigPtr cfg; virQEMUDriverConfigPtr cfg;
int errfd = -1; int errfd = -1;
char *pidfile = NULL; g_autofree char *pidfile = NULL;
int pidfd = -1; int pidfd = -1;
char *socketPath = NULL; g_autofree char *socketPath = NULL;
pid_t cpid = -1; pid_t cpid = -1;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
virTimeBackOffVar timebackoff; virTimeBackOffVar timebackoff;
@ -2948,9 +2936,7 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
unlink(pidfile); unlink(pidfile);
} }
virCommandFree(cmd); virCommandFree(cmd);
VIR_FREE(socketPath);
VIR_FORCE_CLOSE(pidfd); VIR_FORCE_CLOSE(pidfd);
VIR_FREE(pidfile);
VIR_FORCE_CLOSE(errfd); VIR_FORCE_CLOSE(errfd);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
@ -3366,7 +3352,7 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
int oldReason; int oldReason;
int newReason; int newReason;
bool running; bool running;
char *msg = NULL; g_autofree char *msg = NULL;
int ret; int ret;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
@ -3414,7 +3400,6 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
NULLSTR(msg), NULLSTR(msg),
virDomainStateTypeToString(newState), virDomainStateTypeToString(newState),
virDomainStateReasonToString(newState, newReason)); virDomainStateReasonToString(newState, newReason));
VIR_FREE(msg);
virDomainObjSetState(vm, newState, newReason); virDomainObjSetState(vm, newState, newReason);
} }
@ -3879,7 +3864,6 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
bool build) bool build)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
char *path = NULL;
size_t i; size_t i;
bool shouldBuildHP = false; bool shouldBuildHP = false;
bool shouldBuildMB = false; bool shouldBuildMB = false;
@ -3892,6 +3876,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
if (!build || shouldBuildHP) { if (!build || shouldBuildHP) {
for (i = 0; i < cfg->nhugetlbfs; i++) { for (i = 0; i < cfg->nhugetlbfs; i++) {
g_autofree char *path = NULL;
path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]); path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]);
if (!path) if (!path)
@ -3900,25 +3885,21 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm, if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
path, build) < 0) path, build) < 0)
goto cleanup; goto cleanup;
VIR_FREE(path);
} }
} }
if (!build || shouldBuildMB) { if (!build || shouldBuildMB) {
g_autofree char *path = NULL;
if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0) if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0)
goto cleanup; goto cleanup;
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm, if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
path, build) < 0) path, build) < 0)
goto cleanup; goto cleanup;
VIR_FREE(path);
} }
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -3930,7 +3911,7 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
virDomainMemoryDefPtr mem) virDomainMemoryDefPtr mem)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
char *path = NULL; g_autofree char *path = NULL;
int ret = -1; int ret = -1;
if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0) if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0)
@ -3944,7 +3925,6 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -4079,11 +4059,12 @@ static int
qemuProcessVerifyHypervFeatures(virDomainDefPtr def, qemuProcessVerifyHypervFeatures(virDomainDefPtr def,
virCPUDataPtr cpu) virCPUDataPtr cpu)
{ {
char *cpuFeature;
size_t i; size_t i;
int rc; int rc;
for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) { for (i = 0; i < VIR_DOMAIN_HYPERV_LAST; i++) {
g_autofree char *cpuFeature = NULL;
/* always supported string property */ /* always supported string property */
if (i == VIR_DOMAIN_HYPERV_VENDOR_ID || if (i == VIR_DOMAIN_HYPERV_VENDOR_ID ||
i == VIR_DOMAIN_HYPERV_SPINLOCKS) i == VIR_DOMAIN_HYPERV_SPINLOCKS)
@ -4095,7 +4076,6 @@ qemuProcessVerifyHypervFeatures(virDomainDefPtr def,
cpuFeature = g_strdup_printf("hv-%s", virDomainHypervTypeToString(i)); cpuFeature = g_strdup_printf("hv-%s", virDomainHypervTypeToString(i));
rc = virCPUDataCheckFeature(cpu, cpuFeature); rc = virCPUDataCheckFeature(cpu, cpuFeature);
VIR_FREE(cpuFeature);
if (rc < 0) { if (rc < 0) {
return -1; return -1;
@ -4518,17 +4498,17 @@ qemuLogOperation(virDomainObjPtr vm,
virCommandPtr cmd, virCommandPtr cmd,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt)
{ {
char *timestamp; g_autofree char *timestamp = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int qemuVersion = virQEMUCapsGetVersion(priv->qemuCaps); int qemuVersion = virQEMUCapsGetVersion(priv->qemuCaps);
const char *package = virQEMUCapsGetPackage(priv->qemuCaps); const char *package = virQEMUCapsGetPackage(priv->qemuCaps);
char *hostname = virGetHostname(); g_autofree char *hostname = virGetHostname();
struct utsname uts; struct utsname uts;
uname(&uts); uname(&uts);
if ((timestamp = virTimeStringNow()) == NULL) if ((timestamp = virTimeStringNow()) == NULL)
goto cleanup; return;
if (qemuDomainLogContextWrite(logCtxt, if (qemuDomainLogContextWrite(logCtxt,
"%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n", "%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n",
@ -4539,17 +4519,12 @@ qemuLogOperation(virDomainObjPtr vm,
NULLSTR_EMPTY(package), NULLSTR_EMPTY(package),
uts.release, uts.release,
NULLSTR_EMPTY(hostname)) < 0) NULLSTR_EMPTY(hostname)) < 0)
goto cleanup; return;
if (cmd) { if (cmd) {
char *args = virCommandToString(cmd, true); g_autofree char *args = virCommandToString(cmd, true);
qemuDomainLogContextWrite(logCtxt, "%s\n", args); qemuDomainLogContextWrite(logCtxt, "%s\n", args);
VIR_FREE(args);
} }
cleanup:
VIR_FREE(hostname);
VIR_FREE(timestamp);
} }
@ -4647,7 +4622,7 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
virHookSubopType subop) virHookSubopType subop)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char *xml; g_autofree char *xml = NULL;
int ret; int ret;
if (!virHookPresent(VIR_HOOK_DRIVER_QEMU)) if (!virHookPresent(VIR_HOOK_DRIVER_QEMU))
@ -4658,7 +4633,6 @@ qemuProcessStartHook(virQEMUDriverPtr driver,
ret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, op, subop, ret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, op, subop,
NULL, xml, NULL); NULL, xml, NULL);
VIR_FREE(xml);
return ret; return ret;
} }
@ -4771,7 +4745,7 @@ qemuProcessGetNetworkAddress(const char *netname,
virSocketAddr addr; virSocketAddr addr;
virSocketAddrPtr addrptr = NULL; virSocketAddrPtr addrptr = NULL;
char *dev_name = NULL; char *dev_name = NULL;
char *xml = NULL; g_autofree char *xml = NULL;
*netaddr = NULL; *netaddr = NULL;
@ -4853,7 +4827,6 @@ qemuProcessGetNetworkAddress(const char *netname,
virNetworkDefFree(netdef); virNetworkDefFree(netdef);
virObjectUnref(net); virObjectUnref(net);
virObjectUnref(conn); virObjectUnref(conn);
VIR_FREE(xml);
return ret; return ret;
} }
@ -6392,7 +6365,7 @@ qemuProcessSEVCreateFile(virDomainObjPtr vm,
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverPtr driver = priv->driver; virQEMUDriverPtr driver = priv->driver;
char *configFile; g_autofree char *configFile = NULL;
int ret = -1; int ret = -1;
if (!(configFile = virFileBuildPath(priv->libDir, name, ".base64"))) if (!(configFile = virFileBuildPath(priv->libDir, name, ".base64")))
@ -6409,7 +6382,6 @@ qemuProcessSEVCreateFile(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(configFile);
return ret; return ret;
} }
@ -6746,7 +6718,7 @@ qemuProcessLaunch(virConnectPtr conn,
struct qemuProcessHookData hookData; struct qemuProcessHookData hookData;
virQEMUDriverConfigPtr cfg; virQEMUDriverConfigPtr cfg;
size_t nnicindexes = 0; size_t nnicindexes = 0;
int *nicindexes = NULL; g_autofree int *nicindexes = NULL;
size_t i; size_t i;
VIR_DEBUG("conn=%p driver=%p vm=%p name=%s if=%d asyncJob=%d " VIR_DEBUG("conn=%p driver=%p vm=%p name=%s if=%d asyncJob=%d "
@ -7053,7 +7025,6 @@ qemuProcessLaunch(virConnectPtr conn,
virCommandFree(cmd); virCommandFree(cmd);
virObjectUnref(logCtxt); virObjectUnref(logCtxt);
virObjectUnref(cfg); virObjectUnref(cfg);
VIR_FREE(nicindexes);
return ret; return ret;
} }
@ -7374,7 +7345,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virDomainDefPtr def = vm->def; virDomainDefPtr def = vm->def;
const virNetDevVPortProfile *vport = NULL; const virNetDevVPortProfile *vport = NULL;
size_t i; size_t i;
char *timestamp; g_autofree char *timestamp = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
@ -7417,7 +7388,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
qemuDomainLogAppendMessage(driver, vm, "%s: shutting down, reason=%s\n", qemuDomainLogAppendMessage(driver, vm, "%s: shutting down, reason=%s\n",
timestamp, timestamp,
virDomainShutoffReasonTypeToString(reason)); virDomainShutoffReasonTypeToString(reason));
VIR_FREE(timestamp);
} }
/* Clear network bandwidth */ /* Clear network bandwidth */
@ -7488,13 +7458,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
/* now that we know it's stopped call the hook if present */ /* now that we know it's stopped call the hook if present */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, NULL, vm->def, 0); g_autofree char *xml = qemuDomainDefFormatXML(driver, NULL, vm->def, 0);
/* we can't stop the operation even if the script raised an error */ /* we can't stop the operation even if the script raised an error */
ignore_value(virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, ignore_value(virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END, VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END,
NULL, xml, NULL)); NULL, xml, NULL));
VIR_FREE(xml);
} }
/* Reset Security Labels unless caller don't want us to */ /* Reset Security Labels unless caller don't want us to */
@ -7677,13 +7646,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
/* The "release" hook cleans up additional resources */ /* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, NULL, vm->def, 0); g_autofree char *xml = qemuDomainDefFormatXML(driver, NULL, vm->def, 0);
/* we can't stop the operation even if the script raised an error */ /* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
VIR_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END, VIR_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END,
NULL, xml, NULL); NULL, xml, NULL);
VIR_FREE(xml);
} }
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
@ -8228,13 +8196,14 @@ qemuProcessReconnect(void *opaque)
/* Run an hook to allow admins to do some magic */ /* Run an hook to allow admins to do some magic */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, priv->qemuCaps, obj->def, 0); g_autofree char *xml = qemuDomainDefFormatXML(driver,
priv->qemuCaps,
obj->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name,
VIR_HOOK_QEMU_OP_RECONNECT, VIR_HOOK_SUBOP_BEGIN, VIR_HOOK_QEMU_OP_RECONNECT, VIR_HOOK_SUBOP_BEGIN,
NULL, xml, NULL); NULL, xml, NULL);
VIR_FREE(xml);
/* /*
* If the script raised an error abort the launch * If the script raised an error abort the launch
@ -8489,7 +8458,7 @@ qemuProcessQEMULabelUniqPath(qemuProcessQMPPtr proc)
static int static int
qemuProcessQMPInit(qemuProcessQMPPtr proc) qemuProcessQMPInit(qemuProcessQMPPtr proc)
{ {
char *template = NULL; g_autofree char *template = NULL;
VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary); VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary);
@ -8502,6 +8471,10 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc)
template); template);
return -1; return -1;
} }
/* if g_mkdtemp succeeds, proc->uniqDir is now the owner of
* the string. Set template to NULL to avoid freeing
* the memory in this case */
template = NULL;
if (qemuProcessQEMULabelUniqPath(proc) < 0) if (qemuProcessQEMULabelUniqPath(proc) < 0)
return -1; return -1;