Re: [PATCH v2 3/6] netdev_bandwidth_conf: Refractor virNetDevBandwidthParse()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On a Wednesday in 2021, Kristina Hanicova wrote:
Refractoring includes:
* removal of VIR_FREE
* inversion of the condition

* use of g_steal_pointer

The conversion to g_steal_pointer was in your patch:
    Use g_steal_pointer where possible
and is already merged as
commit 155151a3d061e36417095f6fc09db3471a9eaa47

Jano


Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
src/conf/netdev_bandwidth_conf.c | 9 +++------
src/util/virnetdevbandwidth.h    | 2 ++
2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c
index 1ff3785677..81590efe6d 100644
--- a/src/conf/netdev_bandwidth_conf.c
+++ b/src/conf/netdev_bandwidth_conf.c
@@ -111,7 +111,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
                        bool allowFloor)
{
    int ret = -1;
-    virNetDevBandwidthPtr def = NULL;
+    g_autoptr(virNetDevBandwidth) def = NULL;
    xmlNodePtr cur;
    xmlNodePtr in = NULL, out = NULL;
    g_autofree char *class_id_prop = NULL;
@@ -197,15 +197,12 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
        }
    }

-    if (!def->in && !def->out)
-        VIR_FREE(def);
+    if (def->in || def->out)
+        *bandwidth = g_steal_pointer(&def);

-    *bandwidth = def;
-    def = NULL;
    ret = 0;

 cleanup:
-    virNetDevBandwidthFree(def);
    return ret;
}

diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h
index 871d0c962c..fff83222a9 100644
--- a/src/util/virnetdevbandwidth.h
+++ b/src/util/virnetdevbandwidth.h
@@ -38,6 +38,8 @@ struct _virNetDevBandwidth {

void virNetDevBandwidthFree(virNetDevBandwidthPtr def);

+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevBandwidth, virNetDevBandwidthFree);
+
int virNetDevBandwidthSet(const char *ifname,
                          const virNetDevBandwidth *bandwidth,
                          bool hierarchical_class,
--
2.29.2

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux