[libvirt] [PATCH] network: eliminate potential memory leak on parse failure
Daniel Veillard
veillard at redhat.com
Thu Aug 11 06:25:02 UTC 2011
On Thu, Aug 11, 2011 at 12:14:41AM -0400, Laine Stump wrote:
> While the first encountered dns host record is being parsed, it's
> possible for virNetworkDef::hosts to point to memory that has been
> allocated, but virNetworkDef::nhosts to still be 0. If there is a
> failure during that time, virNetworkDef::hosts will be leaked.
>
> Although this isn't currently the case for virNetworkDef::txtrecords,
> it could become that way through future re-factoring, and it hurts
> nothing to restructure the freeing of txtrecord data to match that of
> hosts data.
> ---
> src/conf/network_conf.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index b11c482..e055094 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -127,16 +127,16 @@ static void virNetworkDNSDefFree(virNetworkDNSDefPtr def)
> VIR_FREE(def->txtrecords[def->ntxtrecords].name);
> VIR_FREE(def->txtrecords[def->ntxtrecords].value);
> }
> - VIR_FREE(def->txtrecords);
> }
> + VIR_FREE(def->txtrecords);
> if (def->nhosts) {
> while (def->nhosts--) {
> while (def->hosts[def->nhosts].nnames--)
> VIR_FREE(def->hosts[def->nhosts].names[def->hosts[def->nhosts].nnames]);
> VIR_FREE(def->hosts[def->nhosts].names);
> }
> - VIR_FREE(def->hosts);
> }
> + VIR_FREE(def->hosts);
> VIR_FREE(def);
> }
> }
ACK
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list