[libvirt] [PATCH 0/4] Memory leak fixes
Ján Tomko (4): Fix leak in x86UpdateHostModel Fixes for domains with no iothreads audit: remove redundant NULL assignment audit: fix memory leak without WITH_AUDIT src/cpu/cpu_x86.c | 4 +++- src/qemu/qemu_cgroup.c | 2 +- src/qemu/qemu_process.c | 6 ++++-- src/util/viraudit.c | 13 +++---------- 4 files changed, 11 insertions(+), 14 deletions(-) -- 1.8.5.5
Commit de0aeaf introduced a memory leak. --- src/cpu/cpu_x86.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 7571f16..a98a847 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -2094,8 +2094,10 @@ x86UpdateHostModel(virCPUDefPtr guest, * features directly */ for (i = 0; i < guest->nfeatures; i++) { for (feat = map->migrate_blockers; feat; feat = feat->next) { - if (STREQ(feat->name, guest->features[i].name)) + if (STREQ(feat->name, guest->features[i].name)) { + VIR_FREE(guest->features[i].name); VIR_DELETE_ELEMENT_INPLACE(guest->features, i, guest->nfeatures); + } } } -- 1.8.5.5
Plug a memory leak and silence a warning. --- src/qemu/qemu_cgroup.c | 2 +- src/qemu/qemu_process.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 9d39370..7c6b2c1 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -1131,7 +1131,7 @@ qemuSetupCgroupForIOThreads(virDomainObjPtr vm) if (priv->cgroup == NULL) return 0; - if (priv->niothreadpids == 0) { + if (def->iothreads && priv->niothreadpids == 0) { VIR_WARN("Unable to get iothreads' pids."); return 0; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8853d27..c5b6263 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2117,8 +2117,10 @@ qemuProcessDetectIOThreadPIDs(virQEMUDriverPtr driver, goto cleanup; /* Nothing to do */ - if (niothreads == 0) - return 0; + if (niothreads == 0) { + ret = 0; + goto cleanup; + } if (niothreads != vm->def->iothreads) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 1.8.5.5
virVasprintf sets the output to NULL on failure. --- src/util/viraudit.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 8023c60..d0ad9b9 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -99,10 +99,8 @@ void virAuditSend(virLogSourcePtr source, #endif va_start(args, fmt); - if (virVasprintf(&str, fmt, args) < 0) { + if (virVasprintf(&str, fmt, args) < 0) VIR_WARN("Out of memory while formatting audit message"); - str = NULL; - } va_end(args); if (auditlog && str) { -- 1.8.5.5
Free str unconditionally since we allocate it without WITH_AUDIT too. --- src/util/viraudit.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/util/viraudit.c b/src/util/viraudit.c index d0ad9b9..23928fd 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -115,12 +115,7 @@ void virAuditSend(virLogSourcePtr source, } #if WITH_AUDIT - if (auditfd < 0) { - VIR_FREE(str); - return; - } - - if (str) { + if (str && auditfd >= 0) { static const int record_types[] = { [VIR_AUDIT_RECORD_MACHINE_CONTROL] = AUDIT_VIRT_CONTROL, [VIR_AUDIT_RECORD_MACHINE_ID] = AUDIT_VIRT_MACHINE_ID, @@ -135,9 +130,9 @@ void virAuditSend(virLogSourcePtr source, VIR_WARN("Failed to send audit message %s: %s", NULLSTR(str), virStrerror(errno, ebuf, sizeof(ebuf))); } - VIR_FREE(str); } #endif + VIR_FREE(str); } void virAuditClose(void) -- 1.8.5.5
participants (2)
-
Ján Tomko -
Peter Krempa