[libvirt] [PATCH 0/2] Resolve a couple of Coverity issues

One new one and one that I've seen periodically. John Ferlan (2): security: Resolve Coverity RESOURCE_LEAK libxl: Resolve Coverity CHECKED_RETURN src/libxl/libxl_domain.c | 6 +++++- src/security/security_manager.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) -- 2.1.0

Introduced by commit id 'c3d9d3bb' - return from virSecurityManagerCheckModel wasn't VIR_FREE()'ing the virSecurityManagerGetNested allocated memory. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/security/security_manager.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f2a32bc..12663ad 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -688,24 +688,31 @@ virSecurityManagerReleaseLabel(virSecurityManagerPtr mgr, static int virSecurityManagerCheckModel(virSecurityManagerPtr mgr, char *secmodel) { + int ret = -1; size_t i; virSecurityManagerPtr *sec_managers = NULL; if ((sec_managers = virSecurityManagerGetNested(mgr)) == NULL) return -1; - if (STREQ_NULLABLE(secmodel, "none")) - return 0; + if (STREQ_NULLABLE(secmodel, "none")) { + ret = 0; + goto cleanup; + } for (i = 0; sec_managers[i]; i++) { - if (STREQ_NULLABLE(secmodel, sec_managers[i]->drv->name)) - return 0; + if (STREQ_NULLABLE(secmodel, sec_managers[i]->drv->name)) { + ret = 0; + goto cleanup; + } } virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unable to find security driver for model %s"), secmodel); - return -1; + cleanup: + VIR_FREE(sec_managers); + return ret; } -- 2.1.0

On Fri, Feb 13, 2015 at 03:21:39PM -0500, John Ferlan wrote:
Introduced by commit id 'c3d9d3bb' - return from virSecurityManagerCheckModel wasn't VIR_FREE()'ing the virSecurityManagerGetNested allocated memory.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/security/security_manager.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f2a32bc..12663ad 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -688,24 +688,31 @@ virSecurityManagerReleaseLabel(virSecurityManagerPtr mgr, static int virSecurityManagerCheckModel(virSecurityManagerPtr mgr, char *secmodel) { + int ret = -1; size_t i; virSecurityManagerPtr *sec_managers = NULL;
if ((sec_managers = virSecurityManagerGetNested(mgr)) == NULL) return -1;
- if (STREQ_NULLABLE(secmodel, "none")) - return 0; + if (STREQ_NULLABLE(secmodel, "none")) { + ret = 0; + goto cleanup; + }
I would move the check for secmodel == "none" before virSecurityManagerCheckModel(). We don't need to get security managers if the secmodel is "none" and you can safely return 0.
for (i = 0; sec_managers[i]; i++) { - if (STREQ_NULLABLE(secmodel, sec_managers[i]->drv->name)) - return 0; + if (STREQ_NULLABLE(secmodel, sec_managers[i]->drv->name)) { + ret = 0; + goto cleanup; + } }
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unable to find security driver for model %s"), secmodel); - return -1; + cleanup: + VIR_FREE(sec_managers); + return ret; }
-- 2.1.0
ACK with the change suggested above. Pavel
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Periodically my Coverity scan will return a checked_return failure for libxlDomainShutdownThread call to libxlDomainStart. Followed the libxlAutostartDomain example in order to check the status, emit a message, and continue on. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/libxl/libxl_domain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f0eaf6c..21c41d7 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -685,7 +685,11 @@ libxlDomainShutdownThread(void *opaque) } libxl_domain_destroy(ctx, vm->def->id, NULL); libxlDomainCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN); - libxlDomainStart(driver, vm, 0, -1); + if (libxlDomainStart(driver, vm, false, -1) < 0) { + virErrorPtr err = virGetLastError(); + VIR_ERROR(_("Failed to restart VM '%s': %s"), + vm->def->name, err ? err->message : _("unknown error")); + } cleanup: if (vm) -- 2.1.0

On Fri, Feb 13, 2015 at 03:21:40PM -0500, John Ferlan wrote:
Periodically my Coverity scan will return a checked_return failure for libxlDomainShutdownThread call to libxlDomainStart. Followed the libxlAutostartDomain example in order to check the status, emit a message, and continue on.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/libxl/libxl_domain.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f0eaf6c..21c41d7 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -685,7 +685,11 @@ libxlDomainShutdownThread(void *opaque) } libxl_domain_destroy(ctx, vm->def->id, NULL); libxlDomainCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN); - libxlDomainStart(driver, vm, 0, -1); + if (libxlDomainStart(driver, vm, false, -1) < 0) { + virErrorPtr err = virGetLastError(); + VIR_ERROR(_("Failed to restart VM '%s': %s"), + vm->def->name, err ? err->message : _("unknown error")); + }
cleanup: if (vm) -- 2.1.0
ACK Pavel
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
John Ferlan
-
Pavel Hrdina