From: Osier Yang Date: Mon, 12 Dec 2011 07:26:20 +0000 (+0800) Subject: storage: Fix a potential crash when creating vol object X-Git-Tag: v0.9.9-rc1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=380f326955a25f84dca45b4eead2a7aa4d11e6f2;p=thirdparty%2Flibvirt.git storage: Fix a potential crash when creating vol object If the vol object is newly created, it increases the volumes count, but doesn't decrease the volumes count when do cleanup. It can cause libvirtd to crash when one trying to free the volume objects like: for (i = 0; i < pool->volumes.count; i++) virStorageVolDefFree(pool->volumes.objs[i]); It's more reliable if we add the newly created vol object in the end. --- diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c index d8217174d3..6a235f6833 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -110,7 +110,6 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, virReportOOMError(); goto cleanup; } - pool->volumes.objs[pool->volumes.count++] = vol; } if (vol->target.path == NULL) { @@ -254,6 +253,9 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool, vol->source.nextent++; } + if (is_new_vol) + pool->volumes.objs[pool->volumes.count++] = vol; + ret = 0; cleanup: