X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lib%2Fext2fs%2Ffreefs.c;h=68b8e9a460100757191030825a380e096caccf43;hb=77d77284b56287646e22d926a1e98a2d5b0176f3;hp=8d1da194c70f6b4b54997a542de722b645dac59f;hpb=4cbe8af4b0d0c72fb28bb500c1bd8a46b00fdde3;p=tools%2Fe2fsprogs.git diff --git a/lib/ext2fs/freefs.c b/lib/ext2fs/freefs.c index 8d1da19..68b8e9a 100644 --- a/lib/ext2fs/freefs.c +++ b/lib/ext2fs/freefs.c @@ -1,46 +1,52 @@ /* * freefs.c --- free an ext2 filesystem - * + * * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. * * %Begin-Header% - * This file may be redistributed under the terms of the GNU Public - * License. + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include #endif -#include - -#include +#include "ext2_fs.h" #include "ext2fsP.h" - -static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache); +#include "hashmap.h" void ext2fs_free(ext2_filsys fs) { if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS)) return; + if (fs->image_io != fs->io) { + if (fs->image_io) + io_channel_close(fs->image_io); + } if (fs->io) { io_channel_close(fs->io); } if (fs->device_name) - free(fs->device_name); + ext2fs_free_mem(&fs->device_name); if (fs->super) - free(fs->super); + ext2fs_free_mem(&fs->super); + if (fs->orig_super) + ext2fs_free_mem(&fs->orig_super); if (fs->group_desc) - free(fs->group_desc); + ext2fs_free_mem(&fs->group_desc); if (fs->block_map) ext2fs_free_block_bitmap(fs->block_map); if (fs->inode_map) ext2fs_free_inode_bitmap(fs->inode_map); + if (fs->image_header) + ext2fs_free_mem(&fs->image_header); if (fs->badblocks) - badblocks_list_free(fs->badblocks); + ext2fs_badblocks_list_free(fs->badblocks); fs->badblocks = 0; if (fs->dblist) @@ -48,76 +54,41 @@ void ext2fs_free(ext2_filsys fs) if (fs->icache) ext2fs_free_inode_cache(fs->icache); - - fs->magic = 0; - - free(fs); -} - -void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap) -{ - if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP)) - return; - - bitmap->magic = 0; - if (bitmap->description) { - free(bitmap->description); - bitmap->description = 0; - } - if (bitmap->bitmap) { - free(bitmap->bitmap); - bitmap->bitmap = 0; - } - free(bitmap); -} - -void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap) -{ - if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP)) - return; - bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP; - ext2fs_free_generic_bitmap(bitmap); -} + if (fs->mmp_buf) + ext2fs_free_mem(&fs->mmp_buf); + if (fs->mmp_cmp) + ext2fs_free_mem(&fs->mmp_cmp); -void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap) -{ - if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP)) - return; + if (fs->block_sha_map) + ext2fs_hashmap_free(fs->block_sha_map); - bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP; - ext2fs_free_generic_bitmap(bitmap); -} + fs->magic = 0; -/* - * Free the inode cache structure - */ -static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache) -{ - if (--icache->refcount) - return; - if (icache->buffer) - free(icache->buffer); - if (icache->cache) - free(icache->cache); - icache->buffer_blk = 0; - free(icache); + ext2fs_zero_blocks2(NULL, 0, 0, NULL, NULL); + ext2fs_free_mem(&fs); } /* * This procedure frees a badblocks list. */ -void ext2fs_badblocks_list_free(ext2_badblocks_list bb) +void ext2fs_u32_list_free(ext2_u32_list bb) { if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST) return; if (bb->list) - free(bb->list); + ext2fs_free_mem(&bb->list); bb->list = 0; - free(bb); + ext2fs_free_mem(&bb); +} + +void ext2fs_badblocks_list_free(ext2_badblocks_list bb) +{ + ext2fs_u32_list_free((ext2_u32_list) bb); } + /* * Free a directory block list */ @@ -127,11 +98,11 @@ void ext2fs_free_dblist(ext2_dblist dblist) return; if (dblist->list) - free(dblist->list); + ext2fs_free_mem(&dblist->list); dblist->list = 0; if (dblist->fs && dblist->fs->dblist == dblist) dblist->fs->dblist = 0; dblist->magic = 0; - free(dblist); + ext2fs_free_mem(&dblist); }