]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: avoid freeing network object with undestroyed mutex
authorLaine Stump <laine@laine.org>
Fri, 14 Sep 2012 08:53:54 +0000 (04:53 -0400)
committerLaine Stump <laine@laine.org>
Tue, 18 Sep 2012 00:24:06 +0000 (20:24 -0400)
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.

src/conf/network_conf.c

index d916427b9975d52001c742f000b09eb2280e2357..88e1492f5764df2c7b8aeac4d43187909d18eb34 100644 (file)
@@ -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++;