diff options
Diffstat (limited to 'e2fsprogs/e2fsck.c')
-rw-r--r-- | e2fsprogs/e2fsck.c | 184 |
1 files changed, 57 insertions, 127 deletions
diff --git a/e2fsprogs/e2fsck.c b/e2fsprogs/e2fsck.c index 1c97cf4bb..489d2a818 100644 --- a/e2fsprogs/e2fsck.c +++ b/e2fsprogs/e2fsck.c | |||
@@ -2036,10 +2036,7 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino) | |||
2036 | */ | 2036 | */ |
2037 | static void e2fsck_free_dir_info(e2fsck_t ctx) | 2037 | static void e2fsck_free_dir_info(e2fsck_t ctx) |
2038 | { | 2038 | { |
2039 | if (ctx->dir_info) { | 2039 | ext2fs_free_mem(&ctx->dir_info); |
2040 | ext2fs_free_mem(&ctx->dir_info); | ||
2041 | ctx->dir_info = 0; | ||
2042 | } | ||
2043 | ctx->dir_info_size = 0; | 2040 | ctx->dir_info_size = 0; |
2044 | ctx->dir_info_count = 0; | 2041 | ctx->dir_info_count = 0; |
2045 | } | 2042 | } |
@@ -2178,13 +2175,9 @@ static void e2fsck_free_dx_dir_info(e2fsck_t ctx) | |||
2178 | if (ctx->dx_dir_info) { | 2175 | if (ctx->dx_dir_info) { |
2179 | dir = ctx->dx_dir_info; | 2176 | dir = ctx->dx_dir_info; |
2180 | for (i=0; i < ctx->dx_dir_info_count; i++) { | 2177 | for (i=0; i < ctx->dx_dir_info_count; i++) { |
2181 | if (dir->dx_block) { | 2178 | ext2fs_free_mem(&dir->dx_block); |
2182 | ext2fs_free_mem(&dir->dx_block); | ||
2183 | dir->dx_block = 0; | ||
2184 | } | ||
2185 | } | 2179 | } |
2186 | ext2fs_free_mem(&ctx->dx_dir_info); | 2180 | ext2fs_free_mem(&ctx->dx_dir_info); |
2187 | ctx->dx_dir_info = 0; | ||
2188 | } | 2181 | } |
2189 | ctx->dx_dir_info_size = 0; | 2182 | ctx->dx_dir_info_size = 0; |
2190 | ctx->dx_dir_info_count = 0; | 2183 | ctx->dx_dir_info_count = 0; |
@@ -2245,8 +2238,7 @@ static void ea_refcount_free(ext2_refcount_t refcount) | |||
2245 | if (!refcount) | 2238 | if (!refcount) |
2246 | return; | 2239 | return; |
2247 | 2240 | ||
2248 | if (refcount->list) | 2241 | ext2fs_free_mem(&refcount->list); |
2249 | ext2fs_free_mem(&refcount->list); | ||
2250 | ext2fs_free_mem(&refcount); | 2242 | ext2fs_free_mem(&refcount); |
2251 | } | 2243 | } |
2252 | 2244 | ||
@@ -2259,32 +2251,22 @@ static errcode_t e2fsck_reset_context(e2fsck_t ctx) | |||
2259 | ctx->flags = 0; | 2251 | ctx->flags = 0; |
2260 | ctx->lost_and_found = 0; | 2252 | ctx->lost_and_found = 0; |
2261 | ctx->bad_lost_and_found = 0; | 2253 | ctx->bad_lost_and_found = 0; |
2262 | if (ctx->inode_used_map) { | 2254 | ext2fs_free_inode_bitmap(ctx->inode_used_map); |
2263 | ext2fs_free_inode_bitmap(ctx->inode_used_map); | 2255 | ctx->inode_used_map = 0; |
2264 | ctx->inode_used_map = 0; | 2256 | ext2fs_free_inode_bitmap(ctx->inode_dir_map); |
2265 | } | 2257 | ctx->inode_dir_map = 0; |
2266 | if (ctx->inode_dir_map) { | 2258 | ext2fs_free_inode_bitmap(ctx->inode_reg_map); |
2267 | ext2fs_free_inode_bitmap(ctx->inode_dir_map); | 2259 | ctx->inode_reg_map = 0; |
2268 | ctx->inode_dir_map = 0; | 2260 | ext2fs_free_block_bitmap(ctx->block_found_map); |
2269 | } | 2261 | ctx->block_found_map = 0; |
2270 | if (ctx->inode_reg_map) { | 2262 | ext2fs_free_icount(ctx->inode_link_info); |
2271 | ext2fs_free_inode_bitmap(ctx->inode_reg_map); | 2263 | ctx->inode_link_info = 0; |
2272 | ctx->inode_reg_map = 0; | ||
2273 | } | ||
2274 | if (ctx->block_found_map) { | ||
2275 | ext2fs_free_block_bitmap(ctx->block_found_map); | ||
2276 | ctx->block_found_map = 0; | ||
2277 | } | ||
2278 | if (ctx->inode_link_info) { | ||
2279 | ext2fs_free_icount(ctx->inode_link_info); | ||
2280 | ctx->inode_link_info = 0; | ||
2281 | } | ||
2282 | if (ctx->journal_io) { | 2264 | if (ctx->journal_io) { |
2283 | if (ctx->fs && ctx->fs->io != ctx->journal_io) | 2265 | if (ctx->fs && ctx->fs->io != ctx->journal_io) |
2284 | io_channel_close(ctx->journal_io); | 2266 | io_channel_close(ctx->journal_io); |
2285 | ctx->journal_io = 0; | 2267 | ctx->journal_io = 0; |
2286 | } | 2268 | } |
2287 | if (ctx->fs && ctx->fs->dblist) { | 2269 | if (ctx->fs) { |
2288 | ext2fs_free_dblist(ctx->fs->dblist); | 2270 | ext2fs_free_dblist(ctx->fs->dblist); |
2289 | ctx->fs->dblist = 0; | 2271 | ctx->fs->dblist = 0; |
2290 | } | 2272 | } |
@@ -2292,54 +2274,29 @@ static errcode_t e2fsck_reset_context(e2fsck_t ctx) | |||
2292 | #ifdef ENABLE_HTREE | 2274 | #ifdef ENABLE_HTREE |
2293 | e2fsck_free_dx_dir_info(ctx); | 2275 | e2fsck_free_dx_dir_info(ctx); |
2294 | #endif | 2276 | #endif |
2295 | if (ctx->refcount) { | 2277 | ea_refcount_free(ctx->refcount); |
2296 | ea_refcount_free(ctx->refcount); | 2278 | ctx->refcount = 0; |
2297 | ctx->refcount = 0; | 2279 | ea_refcount_free(ctx->refcount_extra); |
2298 | } | 2280 | ctx->refcount_extra = 0; |
2299 | if (ctx->refcount_extra) { | 2281 | ext2fs_free_block_bitmap(ctx->block_dup_map); |
2300 | ea_refcount_free(ctx->refcount_extra); | 2282 | ctx->block_dup_map = 0; |
2301 | ctx->refcount_extra = 0; | 2283 | ext2fs_free_block_bitmap(ctx->block_ea_map); |
2302 | } | 2284 | ctx->block_ea_map = 0; |
2303 | if (ctx->block_dup_map) { | 2285 | ext2fs_free_inode_bitmap(ctx->inode_bb_map); |
2304 | ext2fs_free_block_bitmap(ctx->block_dup_map); | 2286 | ctx->inode_bb_map = 0; |
2305 | ctx->block_dup_map = 0; | 2287 | ext2fs_free_inode_bitmap(ctx->inode_bad_map); |
2306 | } | 2288 | ctx->inode_bad_map = 0; |
2307 | if (ctx->block_ea_map) { | 2289 | ext2fs_free_inode_bitmap(ctx->inode_imagic_map); |
2308 | ext2fs_free_block_bitmap(ctx->block_ea_map); | 2290 | ctx->inode_imagic_map = 0; |
2309 | ctx->block_ea_map = 0; | 2291 | ext2fs_u32_list_free(ctx->dirs_to_hash); |
2310 | } | 2292 | ctx->dirs_to_hash = 0; |
2311 | if (ctx->inode_bb_map) { | ||
2312 | ext2fs_free_inode_bitmap(ctx->inode_bb_map); | ||
2313 | ctx->inode_bb_map = 0; | ||
2314 | } | ||
2315 | if (ctx->inode_bad_map) { | ||
2316 | ext2fs_free_inode_bitmap(ctx->inode_bad_map); | ||
2317 | ctx->inode_bad_map = 0; | ||
2318 | } | ||
2319 | if (ctx->inode_imagic_map) { | ||
2320 | ext2fs_free_inode_bitmap(ctx->inode_imagic_map); | ||
2321 | ctx->inode_imagic_map = 0; | ||
2322 | } | ||
2323 | if (ctx->dirs_to_hash) { | ||
2324 | ext2fs_u32_list_free(ctx->dirs_to_hash); | ||
2325 | ctx->dirs_to_hash = 0; | ||
2326 | } | ||
2327 | 2293 | ||
2328 | /* | 2294 | /* |
2329 | * Clear the array of invalid meta-data flags | 2295 | * Clear the array of invalid meta-data flags |
2330 | */ | 2296 | */ |
2331 | if (ctx->invalid_inode_bitmap_flag) { | 2297 | ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag); |
2332 | ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag); | 2298 | ext2fs_free_mem(&ctx->invalid_block_bitmap_flag); |
2333 | ctx->invalid_inode_bitmap_flag = 0; | 2299 | ext2fs_free_mem(&ctx->invalid_inode_table_flag); |
2334 | } | ||
2335 | if (ctx->invalid_block_bitmap_flag) { | ||
2336 | ext2fs_free_mem(&ctx->invalid_block_bitmap_flag); | ||
2337 | ctx->invalid_block_bitmap_flag = 0; | ||
2338 | } | ||
2339 | if (ctx->invalid_inode_table_flag) { | ||
2340 | ext2fs_free_mem(&ctx->invalid_inode_table_flag); | ||
2341 | ctx->invalid_inode_table_flag = 0; | ||
2342 | } | ||
2343 | 2300 | ||
2344 | /* Clear statistic counters */ | 2301 | /* Clear statistic counters */ |
2345 | ctx->fs_directory_count = 0; | 2302 | ctx->fs_directory_count = 0; |
@@ -3118,20 +3075,16 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal) | |||
3118 | journal->j_superblock = (journal_superblock_t *)bh->b_data; | 3075 | journal->j_superblock = (journal_superblock_t *)bh->b_data; |
3119 | 3076 | ||
3120 | #ifdef USE_INODE_IO | 3077 | #ifdef USE_INODE_IO |
3121 | if (j_inode) | 3078 | ext2fs_free_mem(&j_inode); |
3122 | ext2fs_free_mem(&j_inode); | ||
3123 | #endif | 3079 | #endif |
3124 | 3080 | ||
3125 | *ret_journal = journal; | 3081 | *ret_journal = journal; |
3126 | return 0; | 3082 | return 0; |
3127 | 3083 | ||
3128 | errout: | 3084 | errout: |
3129 | if (dev_fs) | 3085 | ext2fs_free_mem(&dev_fs); |
3130 | ext2fs_free_mem(&dev_fs); | 3086 | ext2fs_free_mem(&j_inode); |
3131 | if (j_inode) | 3087 | ext2fs_free_mem(&journal); |
3132 | ext2fs_free_mem(&j_inode); | ||
3133 | if (journal) | ||
3134 | ext2fs_free_mem(&journal); | ||
3135 | return retval; | 3088 | return retval; |
3136 | 3089 | ||
3137 | } | 3090 | } |
@@ -3368,11 +3321,9 @@ static void e2fsck_journal_release(e2fsck_t ctx, journal_t *journal, | |||
3368 | } | 3321 | } |
3369 | 3322 | ||
3370 | #ifndef USE_INODE_IO | 3323 | #ifndef USE_INODE_IO |
3371 | if (journal->j_inode) | 3324 | ext2fs_free_mem(&journal->j_inode); |
3372 | ext2fs_free_mem(&journal->j_inode); | ||
3373 | #endif | 3325 | #endif |
3374 | if (journal->j_fs_dev) | 3326 | ext2fs_free_mem(&journal->j_fs_dev); |
3375 | ext2fs_free_mem(&journal->j_fs_dev); | ||
3376 | ext2fs_free_mem(&journal); | 3327 | ext2fs_free_mem(&journal); |
3377 | } | 3328 | } |
3378 | 3329 | ||
@@ -4346,7 +4297,6 @@ static __u64 ext2_max_sizes[EXT2_MAX_BLOCK_LOG_SIZE - | |||
4346 | static void unwind_pass1(void) | 4297 | static void unwind_pass1(void) |
4347 | { | 4298 | { |
4348 | ext2fs_free_mem(&inodes_to_process); | 4299 | ext2fs_free_mem(&inodes_to_process); |
4349 | inodes_to_process = 0; | ||
4350 | } | 4300 | } |
4351 | 4301 | ||
4352 | /* | 4302 | /* |
@@ -5086,10 +5036,8 @@ static void e2fsck_pass1(e2fsck_t ctx) | |||
5086 | handle_fs_bad_blocks(ctx); | 5036 | handle_fs_bad_blocks(ctx); |
5087 | 5037 | ||
5088 | /* We don't need the block_ea_map any more */ | 5038 | /* We don't need the block_ea_map any more */ |
5089 | if (ctx->block_ea_map) { | 5039 | ext2fs_free_block_bitmap(ctx->block_ea_map); |
5090 | ext2fs_free_block_bitmap(ctx->block_ea_map); | 5040 | ctx->block_ea_map = 0; |
5091 | ctx->block_ea_map = 0; | ||
5092 | } | ||
5093 | 5041 | ||
5094 | if (ctx->flags & E2F_FLAG_RESIZE_INODE) { | 5042 | if (ctx->flags & E2F_FLAG_RESIZE_INODE) { |
5095 | ext2fs_block_bitmap save_bmap; | 5043 | ext2fs_block_bitmap save_bmap; |
@@ -7359,14 +7307,10 @@ static void e2fsck_pass2(e2fsck_t ctx) | |||
7359 | ext2fs_free_mem(&buf); | 7307 | ext2fs_free_mem(&buf); |
7360 | ext2fs_free_dblist(fs->dblist); | 7308 | ext2fs_free_dblist(fs->dblist); |
7361 | 7309 | ||
7362 | if (ctx->inode_bad_map) { | 7310 | ext2fs_free_inode_bitmap(ctx->inode_bad_map); |
7363 | ext2fs_free_inode_bitmap(ctx->inode_bad_map); | 7311 | ctx->inode_bad_map = 0; |
7364 | ctx->inode_bad_map = 0; | 7312 | ext2fs_free_inode_bitmap(ctx->inode_reg_map); |
7365 | } | 7313 | ctx->inode_reg_map = 0; |
7366 | if (ctx->inode_reg_map) { | ||
7367 | ext2fs_free_inode_bitmap(ctx->inode_reg_map); | ||
7368 | ctx->inode_reg_map = 0; | ||
7369 | } | ||
7370 | 7314 | ||
7371 | clear_problem_context(&pctx); | 7315 | clear_problem_context(&pctx); |
7372 | if (ctx->large_files) { | 7316 | if (ctx->large_files) { |
@@ -8665,14 +8609,10 @@ static void e2fsck_pass3(e2fsck_t ctx) | |||
8665 | 8609 | ||
8666 | abort_exit: | 8610 | abort_exit: |
8667 | e2fsck_free_dir_info(ctx); | 8611 | e2fsck_free_dir_info(ctx); |
8668 | if (inode_loop_detect) { | 8612 | ext2fs_free_inode_bitmap(inode_loop_detect); |
8669 | ext2fs_free_inode_bitmap(inode_loop_detect); | 8613 | inode_loop_detect = 0; |
8670 | inode_loop_detect = 0; | 8614 | ext2fs_free_inode_bitmap(inode_done_map); |
8671 | } | 8615 | inode_done_map = 0; |
8672 | if (inode_done_map) { | ||
8673 | ext2fs_free_inode_bitmap(inode_done_map); | ||
8674 | inode_done_map = 0; | ||
8675 | } | ||
8676 | 8616 | ||
8677 | #ifdef RESOURCE_TRACK | 8617 | #ifdef RESOURCE_TRACK |
8678 | if (ctx->options & E2F_OPT_TIME2) { | 8618 | if (ctx->options & E2F_OPT_TIME2) { |
@@ -9497,8 +9437,7 @@ static void e2fsck_pass4(e2fsck_t ctx) | |||
9497 | ctx->inode_bb_map = 0; | 9437 | ctx->inode_bb_map = 0; |
9498 | ext2fs_free_inode_bitmap(ctx->inode_imagic_map); | 9438 | ext2fs_free_inode_bitmap(ctx->inode_imagic_map); |
9499 | ctx->inode_imagic_map = 0; | 9439 | ctx->inode_imagic_map = 0; |
9500 | if (buf) | 9440 | ext2fs_free_mem(&buf); |
9501 | ext2fs_free_mem(&buf); | ||
9502 | #ifdef RESOURCE_TRACK | 9441 | #ifdef RESOURCE_TRACK |
9503 | if (ctx->options & E2F_OPT_TIME2) { | 9442 | if (ctx->options & E2F_OPT_TIME2) { |
9504 | e2fsck_clear_progbar(ctx); | 9443 | e2fsck_clear_progbar(ctx); |
@@ -12360,10 +12299,8 @@ static errcode_t alloc_size_dir(ext2_filsys fs, struct out_dir *outdir, | |||
12360 | 12299 | ||
12361 | static void free_out_dir(struct out_dir *outdir) | 12300 | static void free_out_dir(struct out_dir *outdir) |
12362 | { | 12301 | { |
12363 | if (outdir->buf) | 12302 | free(outdir->buf); |
12364 | free(outdir->buf); | 12303 | free(outdir->hashes); |
12365 | if (outdir->hashes) | ||
12366 | free(outdir->hashes); | ||
12367 | outdir->max = 0; | 12304 | outdir->max = 0; |
12368 | outdir->num =0; | 12305 | outdir->num =0; |
12369 | } | 12306 | } |
@@ -12872,14 +12809,10 @@ resort: | |||
12872 | } | 12809 | } |
12873 | 12810 | ||
12874 | retval = write_directory(ctx, fs, &outdir, ino, fd.compress); | 12811 | retval = write_directory(ctx, fs, &outdir, ino, fd.compress); |
12875 | if (retval) | ||
12876 | goto errout; | ||
12877 | 12812 | ||
12878 | errout: | 12813 | errout: |
12879 | if (dir_buf) | 12814 | free(dir_buf); |
12880 | free(dir_buf); | 12815 | free(fd.harray); |
12881 | if (fd.harray) | ||
12882 | free(fd.harray); | ||
12883 | 12816 | ||
12884 | free_out_dir(&outdir); | 12817 | free_out_dir(&outdir); |
12885 | return retval; | 12818 | return retval; |
@@ -12957,8 +12890,7 @@ void e2fsck_rehash_directories(e2fsck_t ctx) | |||
12957 | if (!all_dirs) | 12890 | if (!all_dirs) |
12958 | ext2fs_u32_list_iterate_end(iter); | 12891 | ext2fs_u32_list_iterate_end(iter); |
12959 | 12892 | ||
12960 | if (ctx->dirs_to_hash) | 12893 | ext2fs_u32_list_free(ctx->dirs_to_hash); |
12961 | ext2fs_u32_list_free(ctx->dirs_to_hash); | ||
12962 | ctx->dirs_to_hash = 0; | 12894 | ctx->dirs_to_hash = 0; |
12963 | 12895 | ||
12964 | #ifdef RESOURCE_TRACK | 12896 | #ifdef RESOURCE_TRACK |
@@ -13676,8 +13608,7 @@ static void check_resize_inode(e2fsck_t ctx) | |||
13676 | } | 13608 | } |
13677 | 13609 | ||
13678 | cleanup: | 13610 | cleanup: |
13679 | if (dind_buf) | 13611 | ext2fs_free_mem(&dind_buf); |
13680 | ext2fs_free_mem(&dind_buf); | ||
13681 | 13612 | ||
13682 | } | 13613 | } |
13683 | 13614 | ||
@@ -14639,8 +14570,7 @@ blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name, | |||
14639 | cleanup: | 14570 | cleanup: |
14640 | if (io) | 14571 | if (io) |
14641 | io_channel_close(io); | 14572 | io_channel_close(io); |
14642 | if (buf) | 14573 | ext2fs_free_mem(&buf); |
14643 | ext2fs_free_mem(&buf); | ||
14644 | return (ret_sb); | 14574 | return (ret_sb); |
14645 | } | 14575 | } |
14646 | 14576 | ||