]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: reset the counters to zero
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Thu, 9 Feb 2017 14:13:37 +0000 (15:13 +0100)
committerLaine Stump <laine@laine.org>
Thu, 9 Feb 2017 19:20:42 +0000 (14:20 -0500)
After freeing the data structures we have to reset the counters to
zero. This fixes a segmentation fault when virNetDevIPInfoClear is
called twice (e.g. this is possible in virDomainNetDefParseXML() if
virDomainNetIPInfoParseXML(...) fails with ret < 0 (this leads to the
first call of 'virNetDevIPInfoClear(&def->guestIP)') and the resulting
call of virDomainNetDefFree(def) in the error path of
virDomainNetDefParseXML() (this leads to the second call of
virNetDevIPInfoClear(&def->guestIP), and finally to the segmentation
fault).

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
src/util/virnetdevip.c

index d15976026c9950424c79956f1a2a43fd6c3c51ea..42fbba1eb28a13b7d6a8509a1f0ca331473a1321 100644 (file)
@@ -882,10 +882,12 @@ virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
     for (i = 0; i < ip->nips; i++)
         VIR_FREE(ip->ips[i]);
     VIR_FREE(ip->ips);
+    ip->nips = 0;
 
     for (i = 0; i < ip->nroutes; i++)
         virNetDevIPRouteFree(ip->routes[i]);
     VIR_FREE(ip->routes);
+    ip->nroutes = 0;
 }