From: Kirill Shchetiniuk <kshcheti@redhat.com> Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com> --- src/qemu/qemu_domain.c | 15 ++++++--------- src/qemu/qemu_driver.c | 6 ++---- src/qemu/qemu_migration.c | 25 +++++++++---------------- src/qemu/qemu_monitor.c | 6 ++---- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a42721efad..1fb469e964 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -566,7 +566,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) { g_autofree char *path = NULL; int fd = -1; - uint8_t *masterKey = NULL; + g_autofree uint8_t *masterKey = NULL; ssize_t masterKeyLen = 0; if (!(path = qemuDomainGetMasterKeyFilePath(priv->libDir))) @@ -601,7 +601,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) masterKey = g_renew(uint8_t, masterKey, masterKeyLen); - priv->masterKey = masterKey; + priv->masterKey = g_steal_pointer(&masterKey); priv->masterKeyLen = masterKeyLen; VIR_FORCE_CLOSE(fd); @@ -609,9 +609,7 @@ qemuDomainMasterKeyReadFile(qemuDomainObjPrivate *priv) return 0; error: - if (masterKeyLen > 0) - memset(masterKey, 0, masterKeyLen); - VIR_FREE(masterKey); + virSecureErase(masterKey, masterKeyLen); VIR_FORCE_CLOSE(fd); @@ -3322,7 +3320,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, { qemuDomainObjPrivate *priv = vm->privateData; virQEMUDriver *driver = config->priv; - char *monitorpath; + g_autofree char *monitorpath = NULL; g_autofree char *tmp = NULL; int n; size_t i; @@ -3349,13 +3347,12 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, switch (priv->monConfig->type) { case VIR_DOMAIN_CHR_TYPE_PTY: - priv->monConfig->data.file.path = monitorpath; + priv->monConfig->data.file.path = g_steal_pointer(&monitorpath); break; case VIR_DOMAIN_CHR_TYPE_UNIX: - priv->monConfig->data.nix.path = monitorpath; + priv->monConfig->data.nix.path = g_steal_pointer(&monitorpath); break; default: - VIR_FREE(monitorpath); virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported monitor type '%1$s'"), virDomainChrTypeToString(priv->monConfig->type)); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a1b1edcbbf..12a1b2ae9d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18858,7 +18858,7 @@ qemuDomainGetGuestVcpus(virDomainPtr dom, { virDomainObj *vm = NULL; qemuAgent *agent; - qemuAgentCPUInfo *info = NULL; + g_autofree qemuAgentCPUInfo *info = NULL; int ninfo = 0; int ret = -1; @@ -18892,7 +18892,6 @@ qemuDomainGetGuestVcpus(virDomainPtr dom, virDomainObjEndAgentJob(vm); cleanup: - VIR_FREE(info); virDomainObjEndAPI(&vm); return ret; } @@ -18906,7 +18905,7 @@ qemuDomainSetGuestVcpus(virDomainPtr dom, { virDomainObj *vm = NULL; g_autoptr(virBitmap) map = NULL; - qemuAgentCPUInfo *info = NULL; + g_autofree qemuAgentCPUInfo *info = NULL; qemuAgent *agent; int ninfo = 0; size_t i; @@ -18976,7 +18975,6 @@ qemuDomainSetGuestVcpus(virDomainPtr dom, virDomainObjEndAgentJob(vm); cleanup: - VIR_FREE(info); virDomainObjEndAPI(&vm); return ret; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9109c4526d..fd050641c7 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3852,7 +3852,7 @@ qemuMigrationDstPrepareTunnel(virQEMUDriver *driver, static virURI * qemuMigrationAnyParseURI(const char *uri, bool *wellFormed) { - char *tmp = NULL; + g_autofree char *tmp = NULL; virURI *parsed; /* For compatibility reasons tcp://... URIs are sent as tcp:... @@ -3865,7 +3865,6 @@ qemuMigrationAnyParseURI(const char *uri, bool *wellFormed) parsed = virURIParse(uri); if (parsed && wellFormed) *wellFormed = !tmp; - VIR_FREE(tmp); return parsed; } @@ -4044,18 +4043,16 @@ qemuMigrationAnyPrepareDef(virQEMUDriver *driver, if (!(def = virDomainDefParseString(dom_xml, driver->xmlopt, qemuCaps, VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto cleanup; + return NULL; if (dname) { name = def->name; def->name = g_strdup(dname); } - cleanup: - if (def && origname) - *origname = name; - else - VIR_FREE(name); + if (origname) + *origname = g_steal_pointer(&name); + return def; } @@ -4331,7 +4328,7 @@ struct _qemuMigrationIOThread { static void qemuMigrationSrcIOFunc(void *arg) { qemuMigrationIOThread *data = arg; - char *buffer = NULL; + g_autofree char *buffer = NULL; struct pollfd fds[2]; int timeout = -1; virErrorPtr err = NULL; @@ -4409,7 +4406,6 @@ static void qemuMigrationSrcIOFunc(void *arg) goto error; VIR_FORCE_CLOSE(data->sock); - VIR_FREE(buffer); return; @@ -4428,7 +4424,6 @@ static void qemuMigrationSrcIOFunc(void *arg) if (!virLastErrorIsSystemErrno(EPIPE)) virCopyLastError(&data->err); virResetLastError(); - VIR_FREE(buffer); } @@ -4436,7 +4431,7 @@ static qemuMigrationIOThread * qemuMigrationSrcStartTunnel(virStreamPtr st, int sock) { - qemuMigrationIOThread *io = NULL; + g_autofree qemuMigrationIOThread *io = NULL; int wakeupFD[2] = { -1, -1 }; if (virPipe(wakeupFD) < 0) @@ -4459,12 +4454,11 @@ qemuMigrationSrcStartTunnel(virStreamPtr st, goto error; } - return io; + return g_steal_pointer(&io); error: VIR_FORCE_CLOSE(wakeupFD[0]); VIR_FORCE_CLOSE(wakeupFD[1]); - VIR_FREE(io); return NULL; } @@ -7131,7 +7125,7 @@ qemuMigrationSrcToLegacyFile(virQEMUDriver *driver, qemuDomainObjPrivate *priv = vm->privateData; int ret = -1; int pipeFD[2] = { -1, -1 }; - char *errbuf = NULL; + g_autofree char *errbuf = NULL; if (compressor && virPipe(pipeFD) < 0) return -1; @@ -7177,7 +7171,6 @@ qemuMigrationSrcToLegacyFile(virQEMUDriver *driver, if (errbuf) { VIR_DEBUG("Compression binary stderr: %s", NULLSTR(errbuf)); - VIR_FREE(errbuf); } return ret; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0f1a9d13f5..b6b606963d 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -890,7 +890,7 @@ qemuMonitorInitBalloonObjectPath(qemuMonitor *mon, virDomainMemballoonDef *balloon) { ssize_t i, nprops = 0; - char *path = NULL; + g_autofree char *path = NULL; const char *name; qemuMonitorJSONListPath **bprops = NULL; @@ -970,7 +970,6 @@ qemuMonitorInitBalloonObjectPath(qemuMonitor *mon, for (i = 0; i < nprops; i++) qemuMonitorJSONListPathFree(bprops[i]); VIR_FREE(bprops); - VIR_FREE(path); return; } @@ -2341,7 +2340,7 @@ qemuMonitorMigrateToHost(qemuMonitor *mon, int port) { int ret; - char *uri = NULL; + g_autofree char *uri = NULL; VIR_DEBUG("hostname=%s port=%d flags=0x%x", hostname, port, flags); QEMU_CHECK_MONITOR(mon); @@ -2352,7 +2351,6 @@ qemuMonitorMigrateToHost(qemuMonitor *mon, ret = qemuMonitorJSONMigrate(mon, flags, uri); - VIR_FREE(uri); return ret; } -- 2.49.0