Coverage Report

Created: 2023-09-25 06:05

/src/e2fsprogs/lib/ext2fs/freefs.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * freefs.c --- free an ext2 filesystem
3
 *
4
 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
5
 *
6
 * %Begin-Header%
7
 * This file may be redistributed under the terms of the GNU Library
8
 * General Public License, version 2.
9
 * %End-Header%
10
 */
11
12
#include "config.h"
13
#include <stdio.h>
14
#if HAVE_UNISTD_H
15
#include <unistd.h>
16
#endif
17
18
#include "ext2_fs.h"
19
#include "ext2fsP.h"
20
#include "hashmap.h"
21
22
void ext2fs_free(ext2_filsys fs)
23
885
{
24
885
  if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS))
25
0
    return;
26
885
  if (fs->image_io != fs->io) {
27
0
    if (fs->image_io)
28
0
      io_channel_close(fs->image_io);
29
0
  }
30
885
  if (fs->io) {
31
885
    io_channel_close(fs->io);
32
885
  }
33
885
  if (fs->device_name)
34
885
    ext2fs_free_mem(&fs->device_name);
35
885
  if (fs->super)
36
885
    ext2fs_free_mem(&fs->super);
37
885
  if (fs->orig_super)
38
885
    ext2fs_free_mem(&fs->orig_super);
39
885
  if (fs->group_desc)
40
767
    ext2fs_free_mem(&fs->group_desc);
41
885
  if (fs->block_map)
42
389
    ext2fs_free_block_bitmap(fs->block_map);
43
885
  if (fs->inode_map)
44
22
    ext2fs_free_inode_bitmap(fs->inode_map);
45
885
  if (fs->image_header)
46
0
    ext2fs_free_mem(&fs->image_header);
47
48
885
  if (fs->badblocks)
49
0
    ext2fs_badblocks_list_free(fs->badblocks);
50
885
  fs->badblocks = 0;
51
52
885
  if (fs->dblist)
53
0
    ext2fs_free_dblist(fs->dblist);
54
55
885
  if (fs->icache)
56
0
    ext2fs_free_inode_cache(fs->icache);
57
58
885
  if (fs->mmp_buf)
59
0
    ext2fs_free_mem(&fs->mmp_buf);
60
885
  if (fs->mmp_cmp)
61
0
    ext2fs_free_mem(&fs->mmp_cmp);
62
63
885
  if (fs->block_sha_map)
64
0
    ext2fs_hashmap_free(fs->block_sha_map);
65
66
885
  fs->magic = 0;
67
68
885
  ext2fs_zero_blocks2(NULL, 0, 0, NULL, NULL);
69
885
  ext2fs_free_mem(&fs);
70
885
}
71
72
/*
73
 * This procedure frees a badblocks list.
74
 */
75
void ext2fs_u32_list_free(ext2_u32_list bb)
76
0
{
77
0
  if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST)
78
0
    return;
79
80
0
  if (bb->list)
81
0
    ext2fs_free_mem(&bb->list);
82
0
  bb->list = 0;
83
0
  ext2fs_free_mem(&bb);
84
0
}
85
86
void ext2fs_badblocks_list_free(ext2_badblocks_list bb)
87
0
{
88
0
  ext2fs_u32_list_free((ext2_u32_list) bb);
89
0
}
90
91
92
/*
93
 * Free a directory block list
94
 */
95
void ext2fs_free_dblist(ext2_dblist dblist)
96
0
{
97
0
  if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST))
98
0
    return;
99
100
0
  if (dblist->list)
101
0
    ext2fs_free_mem(&dblist->list);
102
0
  dblist->list = 0;
103
0
  if (dblist->fs && dblist->fs->dblist == dblist)
104
0
    dblist->fs->dblist = 0;
105
0
  dblist->magic = 0;
106
0
  ext2fs_free_mem(&dblist);
107
0
}
108