]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Fix a potential crash when creating vol object
authorOsier Yang <jyang@redhat.com>
Mon, 12 Dec 2011 07:26:20 +0000 (15:26 +0800)
committerOsier Yang <jyang@redhat.com>
Tue, 13 Dec 2011 03:14:26 +0000 (11:14 +0800)
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.

src/storage/storage_backend_logical.c

index d8217174d3e9e4d9ff39f7346b5e3a780bb0030a..6a235f683347f07ab82322d2c366d3904bfaccbf 100644 (file)
@@ -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: