]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: avoid null deref and leak on failure
authorEric Blake <eblake@redhat.com>
Tue, 3 May 2011 17:44:04 +0000 (11:44 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 4 May 2011 21:01:13 +0000 (15:01 -0600)
Detected by clang.  NULL deref added in commit 343a27a (Mar 11),
but leak of voldef present since commit 2cd9b2d (Apr 09).

* src/storage/storage_driver.c (storageVolumeCreateXML): Don't
leak voldef or dereference null volobj.

src/storage/storage_driver.c

index 1ea5d120d05eb885b9750f46c30d065b78a74b2a..5118ffb1ec1f4f85ba22473499b44e0c9a2035bb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * storage_driver.c: core driver for storage APIs
  *
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -1319,8 +1319,12 @@ storageVolumeCreateXML(virStoragePoolPtr obj,
     pool->volumes.objs[pool->volumes.count++] = voldef;
     volobj = virGetStorageVol(obj->conn, pool->def->name, voldef->name,
                               voldef->key);
+    if (!volobj) {
+        pool->volumes.count--;
+        goto cleanup;
+    }
 
-    if (volobj && backend->buildVol) {
+    if (backend->buildVol) {
         int buildret;
         virStorageVolDefPtr buildvoldef = NULL;