]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Fix memory leak on metadata fetching
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 28 Jul 2011 13:42:57 +0000 (15:42 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 28 Jul 2011 14:01:39 +0000 (16:01 +0200)
As written in virStorageFileGetMetadataFromFD decription, caller
must free metadata after use. Qemu driver miss this and therefore
leak metadata which can grow to huge mem leak if somebody query
for blockInfo a lot.

src/qemu/qemu_driver.c

index 0f9191023c11aceb58032dd879f5d8176d10c7fa..d45c7c56acaa0d1df4b0b1350d353f9d6156670b 100644 (file)
@@ -6949,7 +6949,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
     int ret = -1;
     int fd = -1;
     off_t end;
-    virStorageFileMetadata meta;
+    virStorageFileMetadata *meta = NULL;
     virDomainDiskDefPtr disk = NULL;
     struct stat sb;
     int i;
@@ -7017,9 +7017,14 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
         }
     }
 
+    if (VIR_ALLOC(meta) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
     if (virStorageFileGetMetadataFromFD(path, fd,
                                         format,
-                                        &meta) < 0)
+                                        meta) < 0)
         goto cleanup;
 
     /* Get info for normal formats */
@@ -7056,8 +7061,8 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
 
     /* If the file we probed has a capacity set, then override
      * what we calculated from file/block extents */
-    if (meta.capacity)
-        info->capacity = meta.capacity;
+    if (meta->capacity)
+        info->capacity = meta->capacity;
 
     /* Set default value .. */
     info->allocation = info->physical;
@@ -7091,6 +7096,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
     }
 
 cleanup:
+    virStorageFileFreeMetadata(meta);
     VIR_FORCE_CLOSE(fd);
     if (vm)
         virDomainObjUnlock(vm);