[PATCH] conf: convert network_conf.c to use g_auto* pointers

Erik Skultety eskultet at redhat.com
Thu Jun 11 06:59:24 UTC 2020


On Thu, Jun 11, 2020 at 12:09:34AM -0400, Laine Stump wrote:
> On 6/10/20 3:51 AM, Erik Skultety wrote:
> > On Wed, Jun 10, 2020 at 12:16:50AM -0400, Laine Stump wrote:
> > > This was mostly boilerplate conversion, but in one case I needed to
> > > define several differently named char* to take the place of a single
> > > char *tmp that was re-used multiple times, and in another place there
> > > was a single char* that was used at the toplevel of the function, and
> > > then later used repeatedly inside a for loop, so I defined a new
> > > separate char* inside the loop.
> > >
> > > Signed-off-by: Laine Stump <laine at redhat.com>
> > > ---
> > >
> > > This should be applied on top of Dan's IPv6 NAT patch series (it was
> > > reviewing that series that showed me this file hadn't yet been
> > > converted).
> > ...
> >
> > > @@ -689,14 +678,12 @@ virNetworkDHCPDefParseXML(const char *networkName,
> > >               if (server &&
> > >                   virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) {
> > > -                VIR_FREE(file);
> > > -                VIR_FREE(server);
> > >                   goto cleanup;
> > >               }
> > >               def->bootfile = file;
> > > +            file = NULL;
> > g_steal_pointer would do as well
> >
> > Reviewed-by: Erik Skultety <eskultet at redhat.com>
> >
>
> Well, Duh! Where was my brain while I was doing that mindless conversion??
>
>
> This made me realized there's actually several places with the x = y; y =
> NULL; pattern associated with no-autofree'd pointers. If it's okay with you,
> I'll squash the following into the patch before I push it (or, if you'd
> prefer I can push it separately):

Yeah, looking at the diff, it would be better to push it in a separate patch.

> From ba0a291015766d74eacb81104abf63a85c0690a0 Mon Sep 17 00:00:00 2001
> From: Laine Stump <laine at redhat.com>
> Date: Thu, 11 Jun 2020 00:04:39 -0400
> Subject: [PATCH] conf: use g_steal_pointer in network_conf.c
>
> Signed-off-by: Laine Stump <laine at redhat.com>
> ---
>  src/conf/network_conf.c | 21 +++++++--------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
>
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index 290111be59..538f038279 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -617,12 +617,9 @@ virNetworkDHCPHostDefParseXML(const char *networkName,
>          cur = cur->next;
>      }
>
> -    host->mac = mac;
> -    mac = NULL;
> -    host->id = id;
> -    id = NULL;
> -    host->name = name;
> -    name = NULL;
> +    host->mac = g_steak_pointer(&mac);

s/steak/steal

Reviewed-by: Erik Skultety <eskultet at redhat.com>


> +    host->id = g_steal_pointer(&id);
> +    host->name = g_steal_pointer(&name);
>      if (ip)
>          host->ip = inaddr;
>
> @@ -681,8 +678,7 @@ virNetworkDHCPDefParseXML(const char *networkName,
>                  goto cleanup;
>              }
>
> -            def->bootfile = file;
> -            file = NULL;
> +            def->bootfile = g_steal_pointer(&file);
>              def->bootserver = inaddr;
>          }
>
> @@ -1542,9 +1538,8 @@ virNetworkForwardDefParseXML(const char *networkName,
>              return -1;
>
>          if (forwardDev) {
> -            def->ifs[0].device.dev = forwardDev;
> +            def->ifs[0].device.dev = g_steal_pointer(&forwardDev);
>              def->ifs[0].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
> -            forwardDev = NULL;
>              def->nifs++;
>          }
>
> @@ -1585,8 +1580,7 @@ virNetworkForwardDefParseXML(const char *networkName,
>                  }
>              }
>
> -            def->ifs[i].device.dev = forwardDevi;
> -            forwardDevi = NULL;
> +            def->ifs[i].device.dev = g_steal_pointer(&forwardDevi);
>              def->ifs[i].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV;
>              def->nifs++;
>          }
> @@ -1662,8 +1656,7 @@ virNetworkForwardDefParseXML(const char *networkName,
>              return -1;
>          }
>
> -        def->pfs->dev = forwardDev;
> -        forwardDev = NULL;
> +        def->pfs->dev = g_steal_pointer(&forwardDev);
>          def->npfs++;
>      }
>
> --
> 2.25.4
>




More information about the libvir-list mailing list