- /* Make sure all the expected images were found. (We already have
- * returned false if *extra* images were found) */
- if (w->current_image != w->hdr.image_count && w->hdr.part_number == 1) {
- ERROR("Only found %u images in WIM, but expected %u",
- w->current_image, w->hdr.image_count);
- return WIMLIB_ERR_IMAGE_COUNT;
+void
+destroy_image_metadata(struct wim_image_metadata *imd,
+ struct wim_lookup_table *table,
+ bool free_metadata_lte)
+{
+ free_dentry_tree(imd->root_dentry, table);
+ imd->root_dentry = NULL;
+ free_wim_security_data(imd->security_data);
+ imd->security_data = NULL;
+
+ if (free_metadata_lte) {
+ free_lookup_table_entry(imd->metadata_lte);
+ imd->metadata_lte = NULL;
+ }
+ if (!table) {
+ struct wim_lookup_table_entry *lte, *tmp;
+ list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, unhashed_list)
+ free_lookup_table_entry(lte);
+ }
+ INIT_LIST_HEAD(&imd->unhashed_streams);
+ INIT_LIST_HEAD(&imd->inode_list);
+#ifdef WITH_NTFS_3G
+ if (imd->ntfs_vol) {
+ do_ntfs_umount(imd->ntfs_vol);
+ imd->ntfs_vol = NULL;
+ }
+#endif
+}
+
+void
+put_image_metadata(struct wim_image_metadata *imd,
+ struct wim_lookup_table *table)
+{
+ if (imd && --imd->refcnt == 0) {
+ destroy_image_metadata(imd, table, true);
+ FREE(imd);