]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Resolve resource leak using 'vol' buffer
authorJohn Ferlan <jferlan@redhat.com>
Wed, 9 Jan 2013 14:54:09 +0000 (09:54 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 11 Jan 2013 00:14:36 +0000 (17:14 -0700)
src/storage/storage_backend_rbd.c

index f5c6b0f1b4a8885bc631fccaf387e4a4219dd15c..8a0e517502c482f23f01bc63e95f1dc210d711cd 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * storage_backend_rbd.c: storage backend for RBD (RADOS Block Device) handling
  *
+ * Copyright (C) 2013 Red Hat, Inc.
  * Copyright (C) 2012 Wido den Hollander
  *
  * This library is free software; you can redistribute it and/or
@@ -319,26 +320,31 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
     }
 
     for (i = 0, name = names; name < names + max_size; i++) {
+        virStorageVolDefPtr vol;
+
         if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) {
             virStoragePoolObjClearVols(pool);
             goto out_of_memory;
         }
 
-        virStorageVolDefPtr vol;
+        if (STREQ(name, ""))
+            break;
+
         if (VIR_ALLOC(vol) < 0)
             goto out_of_memory;
 
         vol->name = strdup(name);
-        if (vol->name == NULL)
+        if (vol->name == NULL) {
+            VIR_FREE(vol);
             goto out_of_memory;
-
-        if (STREQ(vol->name, ""))
-            break;
+        }
 
         name += strlen(name) + 1;
 
-        if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0)
+        if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0) {
+            virStorageVolDefFree(vol);
             goto cleanup;
+        }
 
         pool->volumes.objs[pool->volumes.count++] = vol;
     }