Re: [PATCHv2 01/17] conf: reorganize virNetworkDHCPDefParseXML

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

 



On 07/17/2015 02:43 PM, Laine Stump wrote:
> This makes the range and static host array management in
> virNetworkDHCPDefParseXML() more similar to what is done in
> virNetworkDefUpdateIPDHCPRange() and virNetworkDefUpdateIPDHCPHost() -
> they use VIR_APPEND_ELEMENT rather than a combination of
> VIR_REALLOC_N() and separate incrementing of the array size.
>
> The one functional change here is that a memory leak of the contents
> of the last (unsuccessful) virNetworkDHCPHostDef was previously leaked
> in certain failure conditions, but it is now properly cleaned up.
> ---
>
> new in V2

Heh. I just noticed that this patch sneaked in. It's actually not a part
of the PCI controller series, but was sitting on the same branch. I
wouldn't mind pushing it if someone wants to review it, but it isn't at
all urgent.

>
>  src/conf/network_conf.c | 36 +++++++++++++++++++-----------------
>  1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index 31d4463..25b5b81 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -997,33 +997,32 @@ virNetworkDHCPDefParseXML(const char *networkName,
>                            xmlNodePtr node,
>                            virNetworkIpDefPtr def)
>  {
> -
> +    int ret = -1;
>      xmlNodePtr cur;
> +    virSocketAddrRange range;
> +    virNetworkDHCPHostDef host;
> +
> +    memset(&range, 0, sizeof(range));
> +    memset(&host, 0, sizeof(host));
>  
>      cur = node->children;
>      while (cur != NULL) {
>          if (cur->type == XML_ELEMENT_NODE &&
>              xmlStrEqual(cur->name, BAD_CAST "range")) {
>  
> -            if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0)
> -                return -1;
> -            if (virSocketAddrRangeParseXML(networkName, def, cur,
> -                                           &def->ranges[def->nranges]) < 0) {
> -                return -1;
> -            }
> -            def->nranges++;
> +            if (virSocketAddrRangeParseXML(networkName, def, cur, &range) < 0)
> +                goto cleanup;
> +            if (VIR_APPEND_ELEMENT(def->ranges, def->nranges, range) < 0)
> +                goto cleanup;
>  
>          } else if (cur->type == XML_ELEMENT_NODE &&
>              xmlStrEqual(cur->name, BAD_CAST "host")) {
>  
> -            if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0)
> -                return -1;
>              if (virNetworkDHCPHostDefParseXML(networkName, def, cur,
> -                                              &def->hosts[def->nhosts],
> -                                              false) < 0) {
> -                return -1;
> -            }
> -            def->nhosts++;
> +                                              &host, false) < 0)
> +                goto cleanup;
> +            if (VIR_APPEND_ELEMENT(def->hosts, def->nhosts, host) < 0)
> +                goto cleanup;
>  
>          } else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET) &&
>                     cur->type == XML_ELEMENT_NODE &&
> @@ -1043,7 +1042,7 @@ virNetworkDHCPDefParseXML(const char *networkName,
>                  virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) {
>                  VIR_FREE(file);
>                  VIR_FREE(server);
> -                return -1;
> +                goto cleanup;
>              }
>  
>              def->bootfile = file;
> @@ -1054,7 +1053,10 @@ virNetworkDHCPDefParseXML(const char *networkName,
>          cur = cur->next;
>      }
>  
> -    return 0;
> +    ret = 0;
> + cleanup:
> +    virNetworkDHCPHostDefClear(&host);
> +    return ret;
>  }
>  
>  static int

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]