On 01/09/2015 10:27 AM, Michal Privoznik wrote:
On 09.01.2015 15:58, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
> ---
> src/conf/domain_conf.c | 10 ++++++++--
> src/openvz/openvz_driver.c | 1 +
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
ugh... I was putting together something too...
There's more wrong with this code with respect to not checking the
return value from virSocketAddrFormat() as well. If it returns NULL
(which it can), there are going to be even more issues.
If you haven't pushed - I'd like to propose something different.
John
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index d1a483a..eacd687 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -17264,17 +17264,20 @@ virDomainNetIpsFormat(virBufferPtr buf,
> virDomainNetIpDefPtr *ips, size_t nips)
> virSocketAddrPtr address = &ips[i]->address;
> char *ipStr = virSocketAddrFormat(address);
> const char *familyStr = NULL;
> +
> if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET6))
> familyStr = "ipv6";
> else if (VIR_SOCKET_ADDR_IS_FAMILY(address, AF_INET))
> familyStr = "ipv4";
> - virBufferAsprintf(buf, "<ip address='%s'",
> - ipStr);
> +
> + virBufferAsprintf(buf, "<ip address='%s'", ipStr);
> if (familyStr)
> virBufferAsprintf(buf, " family='%s'", familyStr);
> if (ips[i]->prefix != 0)
> virBufferAsprintf(buf, " prefix='%u'",
ips[i]->prefix);
> virBufferAddLit(buf, "/>\n");
> +
> + VIR_FREE(ipStr);
> }
> }
>
> @@ -17306,6 +17309,9 @@ virDomainNetRoutesFormat(virBufferPtr buf,
> virBufferAsprintf(buf, " prefix='%d'",
route->prefix);
>
> virBufferAddLit(buf, "/>\n");
> +
> + VIR_FREE(via);
> + VIR_FREE(to);
you can just move this VIR_FREE(to) right after the last usage of @to,
like you did in the chunk below.
> }
> }
>
> diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
> index c144eca..64f5219 100644
> --- a/src/openvz/openvz_driver.c
> +++ b/src/openvz/openvz_driver.c
> @@ -911,6 +911,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const
> char *vpsid,
> for (i = 0; i < net->nips; i++) {
> char *ipStr = virSocketAddrFormat(&net->ips[i]->address);
> virCommandAddArgList(cmd, "--ipadd", ipStr, NULL);
> + VIR_FREE(ipStr);
> }
> }
>
>
ACK
Michal
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list