- /* Release the reference to the image metadata and decrement reference
- * counts on the blobs referenced by files in the image. */
- put_image_metadata(wim->image_metadata[image - 1], wim->blob_table);
+ /* Release the files and decrement the reference counts of the blobs
+ * they reference. */
+ imd = wim->image_metadata[image - 1];
+ free_dentry_tree(imd->root_dentry, wim->blob_table);
+ imd->root_dentry = NULL;
+
+ /* Deselect the image and release its metadata. */
+ deselect_current_wim_image(wim);
+ put_image_metadata(imd);