[libvirt] [PATCH 0/3] Couple of bhyve driver cleanups

*** BLURB HERE *** Michal Privoznik (3): bhyve_capabilities: Add Semihalf to Copyright Simplify bhyveDriverGetCapabilities() bhyveConnectGetCapabilities: Fix double caps unref src/bhyve/bhyve_capabilities.c | 1 + src/bhyve/bhyve_driver.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) -- 1.9.0

Since b15a2bbd we have the new bhyve_capabilities.[ch] files. However, the copyright is held by both Roman and Semihalf. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/bhyve/bhyve_capabilities.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 678de6c..bbca924 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -2,6 +2,7 @@ * bhyve_capabilities.c: bhyve capabilities module * * Copyright (C) 2014 Roman Bogorodskiy + * Copyright (C) 2014 Semihalf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public -- 1.9.0

The driver passed as the only argument to the function should never be NULL so there's no need to check it. After removing it, the whole function collapses to a single line doing ref over driver capabilities. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/bhyve/bhyve_driver.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 84d1915..6ef9d98 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -2,6 +2,7 @@ * bhyve_driver.c: core driver methods for managing bhyve guests * * Copyright (C) 2014 Roman Bogorodskiy + * Copyright (C) 2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -123,16 +124,10 @@ bhyveAutostartDomains(bhyveConnPtr driver) * Returns: a reference to a virCapsPtr instance or NULL */ static virCapsPtr -bhyveDriverGetCapabilities(bhyveConnPtr driver) +bhyveDriverGetCapabilities(bhyveConnPtr driver ATTRIBUTE_NONNULL) { - virCapsPtr ret = NULL; - if (driver == NULL) - return NULL; - - ret = virObjectRef(driver->caps); - - return ret; + return virObjectRef(driver->caps); } static char * -- 1.9.0

At the beginning of the function we gain a reference to the driver capabilities. Then, we call format function (*) which if failed, unref over caps is called. Then, at the end another unref occurs. * - Moreover, the format was not called over gained caps, but over privconn->caps directly which is not allowed anymore. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/bhyve/bhyve_driver.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 6ef9d98..a5b349a 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -135,22 +135,24 @@ bhyveConnectGetCapabilities(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; virCapsPtr caps; - char *xml; + char *xml = NULL; if (virConnectGetCapabilitiesEnsureACL(conn) < 0) return NULL; - caps = bhyveDriverGetCapabilities(privconn); - if (!caps) + if (!(caps = bhyveDriverGetCapabilities(privconn))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get Capabilities")); + goto cleanup; + } - if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) { - virObjectUnref(caps); + if (!(xml = virCapabilitiesFormatXML(caps))) { virReportOOMError(); + goto cleanup; } - virObjectUnref(caps); + cleanup: + virObjectUnref(caps); return xml; } -- 1.9.0

Michal Privoznik wrote:
Michal Privoznik (3): bhyve_capabilities: Add Semihalf to Copyright Simplify bhyveDriverGetCapabilities() bhyveConnectGetCapabilities: Fix double caps unref
src/bhyve/bhyve_capabilities.c | 1 + src/bhyve/bhyve_driver.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-)
ACK the series. Roman Bogorodskiy
participants (2)
-
Michal Privoznik
-
Roman Bogorodskiy