From: Eric Biggers Date: Sat, 18 Jan 2014 06:49:27 +0000 (-0600) Subject: extract_resource_to_staging_dir(): Fix memory leak X-Git-Tag: v1.6.1~5 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=8d51112e66e90048a944dcc58b01ab6b76e4c02c extract_resource_to_staging_dir(): Fix memory leak Put a reference to the stream's underlying resource when switching the stream to the staging directory. --- diff --git a/include/wimlib/lookup_table.h b/include/wimlib/lookup_table.h index d4a46c7f..a2feebf7 100644 --- a/include/wimlib/lookup_table.h +++ b/include/wimlib/lookup_table.h @@ -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, diff --git a/src/lookup_table.c b/src/lookup_table.c index 4a3bc1e2..098a8aaf 100644 --- a/src/lookup_table.c +++ b/src/lookup_table.c @@ -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(<e->rspec_node); - if (list_empty(<e->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*)<e->file_on_disk != - (void*)<e->staging_file_name); - #endif - case RESOURCE_IN_ATTACHED_BUFFER: - BUILD_BUG_ON((void*)<e->file_on_disk != - (void*)<e->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(<e->rspec_node); + if (list_empty(<e->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*)<e->file_on_disk != + (void*)<e->staging_file_name); +#endif + case RESOURCE_IN_ATTACHED_BUFFER: + BUILD_BUG_ON((void*)<e->file_on_disk != + (void*)<e->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); } } diff --git a/src/mount_image.c b/src/mount_image.c index 7b3a9147..04be3f6f 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -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;