aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaine Stump <laine@laine.org>2012-09-14 04:53:54 -0400
committerLaine Stump <laine@laine.org>2012-09-17 20:24:06 -0400
commit16d9a3df94f21039a9f01d948ba327f36f3c63ab (patch)
treecf8dd164cd7caf0aaa80fd79f83b654d73ef3efc /src
parentconf: separate functions to parse DHCPHostDef and DHCPRangeDef (diff)
downloadlibvirt-16d9a3df94f21039a9f01d948ba327f36f3c63ab.tar.gz
libvirt-16d9a3df94f21039a9f01d948ba327f36f3c63ab.tar.bz2
libvirt-16d9a3df94f21039a9f01d948ba327f36f3c63ab.zip
conf: avoid freeing network object with undestroyed mutex
virNetworkAssignDef was allocating a new network object, initing and grabbing its lock, then potentially freeing it without unlocking or destroying the lock. In practice 1) this will probably never happen, and 2) even if it did, the lock implementation used on most (all?) platforms doesn't actually hold any resources for an initialized or held lock, but it still bothered me, so I moved the realloc that could lead to this bad situation earlier in the function, and now the mutex isn't inited or locked until we are assured of complete success.
Diffstat (limited to 'src')
-rw-r--r--src/conf/network_conf.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d916427b9..88e1492f5 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -245,6 +245,11 @@ virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
return network;
}
+ if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) {
+ virReportOOMError();
+ return NULL;
+ }
+
if (VIR_ALLOC(network) < 0) {
virReportOOMError();
return NULL;
@@ -258,12 +263,6 @@ virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
virNetworkObjLock(network);
network->def = def;
- if (VIR_REALLOC_N(nets->objs, nets->count + 1) < 0) {
- virReportOOMError();
- VIR_FREE(network);
- return NULL;
- }
-
nets->objs[nets->count] = network;
nets->count++;