[PATCH v2 3/6] netdev_bandwidth_conf: Refractor virNetDevBandwidthParse()
Ján Tomko
jtomko at redhat.com
Thu Mar 4 16:33:49 UTC 2021
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 at redhat.com>
>---
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210304/fe97f7f2/attachment-0001.sig>
More information about the libvir-list
mailing list