]> wimlib.net Git - wimlib/commitdiff
extract_resource_to_staging_dir(): Fix memory leak
authorEric Biggers <ebiggers3@gmail.com>
Sat, 18 Jan 2014 06:49:27 +0000 (00:49 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 18 Jan 2014 06:49:27 +0000 (00:49 -0600)
Put a reference to the stream's underlying resource when switching the
stream to the staging directory.

include/wimlib/lookup_table.h
src/lookup_table.c
src/mount_image.c

index d4a46c7f0f442f9a2bca8a6f2e3348909ef37309..a2feebf7e8b7959ee87adc11c0d25bd5945725a0 100644 (file)
@@ -366,6 +366,8 @@ lte_unbind_wim_resource_spec(struct wim_lookup_table_entry *lte)
        lte->resource_location = RESOURCE_NONEXISTENT;
 }
 
+extern void
+lte_put_resource(struct wim_lookup_table_entry *lte);
 
 extern struct wim_lookup_table_entry *
 new_stream_from_data_buffer(const void *buffer, size_t size,
index 4a3bc1e23b4f3f0f4173f9fa0a4ed28a0d3f2a02..098a8aaf194b2dce63a15b97b7127d48e6814c72 100644 (file)
@@ -190,41 +190,47 @@ out_free:
 }
 
 void
-free_lookup_table_entry(struct wim_lookup_table_entry *lte)
+lte_put_resource(struct wim_lookup_table_entry *lte)
 {
-       if (lte) {
-               switch (lte->resource_location) {
-               case RESOURCE_IN_WIM:
-                       list_del(&lte->rspec_node);
-                       if (list_empty(&lte->rspec->stream_list))
-                               FREE(lte->rspec);
-                       break;
-               case RESOURCE_IN_FILE_ON_DISK:
-       #ifdef __WIN32__
-               case RESOURCE_WIN32_ENCRYPTED:
-       #endif
-       #ifdef WITH_FUSE
-               case RESOURCE_IN_STAGING_FILE:
-                       BUILD_BUG_ON((void*)&lte->file_on_disk !=
-                                    (void*)&lte->staging_file_name);
-       #endif
-               case RESOURCE_IN_ATTACHED_BUFFER:
-                       BUILD_BUG_ON((void*)&lte->file_on_disk !=
-                                    (void*)&lte->attached_buffer);
-                       FREE(lte->file_on_disk);
-                       break;
-#ifdef WITH_NTFS_3G
-               case RESOURCE_IN_NTFS_VOLUME:
-                       if (lte->ntfs_loc) {
-                               FREE(lte->ntfs_loc->path);
-                               FREE(lte->ntfs_loc->stream_name);
-                               FREE(lte->ntfs_loc);
-                       }
-                       break;
+       switch (lte->resource_location) {
+       case RESOURCE_IN_WIM:
+               list_del(&lte->rspec_node);
+               if (list_empty(&lte->rspec->stream_list))
+                       FREE(lte->rspec);
+               break;
+       case RESOURCE_IN_FILE_ON_DISK:
+#ifdef __WIN32__
+       case RESOURCE_WIN32_ENCRYPTED:
 #endif
-               default:
-                       break;
+#ifdef WITH_FUSE
+       case RESOURCE_IN_STAGING_FILE:
+               BUILD_BUG_ON((void*)&lte->file_on_disk !=
+                            (void*)&lte->staging_file_name);
+#endif
+       case RESOURCE_IN_ATTACHED_BUFFER:
+               BUILD_BUG_ON((void*)&lte->file_on_disk !=
+                            (void*)&lte->attached_buffer);
+               FREE(lte->file_on_disk);
+               break;
+#ifdef WITH_NTFS_3G
+       case RESOURCE_IN_NTFS_VOLUME:
+               if (lte->ntfs_loc) {
+                       FREE(lte->ntfs_loc->path);
+                       FREE(lte->ntfs_loc->stream_name);
+                       FREE(lte->ntfs_loc);
                }
+               break;
+#endif
+       default:
+               break;
+       }
+}
+
+void
+free_lookup_table_entry(struct wim_lookup_table_entry *lte)
+{
+       if (lte) {
+               lte_put_resource(lte);
                FREE(lte);
        }
 }
index 7b3a91470d7c7c5c6b57df3412a4f49bf6dd9b52..04be3f6f73c8e3ea9b6b87de79959921ee3302b9 100644 (file)
@@ -667,6 +667,7 @@ extract_resource_to_staging_dir(struct wim_inode *inode,
                }
        }
 
+       lte_put_resource(new_lte);
        new_lte->refcnt              = inode->i_nlink;
        new_lte->resource_location   = RESOURCE_IN_STAGING_FILE;
        new_lte->staging_file_name   = staging_file_name;