]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Don't leak metadata on repeated calls of virStorageFileGetMetadata
authorPeter Krempa <pkrempa@redhat.com>
Thu, 18 Jul 2019 14:32:44 +0000 (16:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 18 Jul 2019 15:54:22 +0000 (17:54 +0200)
When querying storage metadata after a block job we re-run
virStorageFileGetMetadata on the top level storage file. This means that
the workers (virStorageFileGetMetadataInternal) must not overwrite any
pointers without freeing them.

This was not considered for src->compat and src->features. Fix it and
add a comment mentioning that.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virstoragefile.c

index 4e2e7540f1e43d18caf7c8427686d63c4f476f1d..a6de6a1e4527c0042c6ad4f6021b654331e4e26e 100644 (file)
@@ -965,7 +965,11 @@ virStorageFileGetEncryptionPayloadOffset(const struct FileEncryptionInfo *info,
  * assuming it has the given FORMAT, populate information into META
  * with information about the file and its backing store. Return format
  * of the backing store as BACKING_FORMAT. PATH and FORMAT have to be
- * pre-populated in META */
+ * pre-populated in META.
+ *
+ * Note that this function may be called repeatedly on @meta, so it must
+ * clean up any existing allocated memory which would be overwritten.
+ */
 int
 virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
                                   char *buf,
@@ -1052,10 +1056,13 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
             return -1;
     }
 
+    virBitmapFree(meta->features);
+    meta->features = NULL;
     if (fileTypeInfo[meta->format].getFeatures != NULL &&
         fileTypeInfo[meta->format].getFeatures(&meta->features, meta->format, buf, len) < 0)
         return -1;
 
+    VIR_FREE(meta->compat);
     if (meta->format == VIR_STORAGE_FILE_QCOW2 && meta->features &&
         VIR_STRDUP(meta->compat, "1.1") < 0)
         return -1;