Whamcloud - gitweb
debugfs, e2fsck, mke2fs: fix miscellaneous memory leaks detected by ASAN
authorTheodore Ts'o <tytso@mit.edu>
Sat, 12 Nov 2016 14:31:56 +0000 (09:31 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 12 Nov 2016 14:31:56 +0000 (09:31 -0500)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/journal.c
e2fsck/e2fsck.c
e2fsck/pass2.c
lib/support/quotaio.c
misc/mke2fs.c

index fcd5d5e..9997c7c 100644 (file)
@@ -655,6 +655,8 @@ static void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
                if (fs->io != fs->journal_io)
                        io_channel_close(fs->journal_io);
                fs->journal_io = NULL;
+               free(fs->journal_name);
+               fs->journal_name = NULL;
        }
 
 #ifndef USE_INODE_IO
index 6fb2f40..5184a17 100644 (file)
@@ -146,6 +146,10 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
                ext2fs_u32_list_free(ctx->encrypted_dirs);
                ctx->encrypted_dirs = 0;
        }
+       if (ctx->inode_count) {
+               ext2fs_free_icount(ctx->inode_count);
+               ctx->inode_count = 0;
+       }
 
        /* Clear statistic counters */
        ctx->fs_directory_count = 0;
index 5020a19..11c19e8 100644 (file)
@@ -121,7 +121,7 @@ void e2fsck_pass2(e2fsck_t ctx)
        if (cd.pctx.errcode) {
                fix_problem(ctx, PR_2_ALLOCATE_ICOUNT, &cd.pctx);
                ctx->flags |= E2F_FLAG_ABORT;
-               return;
+               goto cleanup;
        }
        buf = (char *) e2fsck_allocate_memory(ctx, 2*fs->blocksize,
                                              "directory scan buffer");
@@ -156,17 +156,17 @@ void e2fsck_pass2(e2fsck_t ctx)
        }
 
        if (ctx->flags & E2F_FLAG_RUN_RETURN)
-               return;
+               goto cleanup;
 
        if (cd.pctx.errcode) {
                fix_problem(ctx, PR_2_DBLIST_ITERATE, &cd.pctx);
                ctx->flags |= E2F_FLAG_ABORT;
-               return;
+               goto cleanup;
        }
 
        for (i=0; (dx_dir = e2fsck_dx_dir_info_iter(ctx, &i)) != 0;) {
                if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
-                       return;
+                       goto cleanup;
                if (e2fsck_dir_will_be_rehashed(ctx, dx_dir->ino) ||
                    dx_dir->numblocks == 0)
                        continue;
@@ -285,6 +285,8 @@ void e2fsck_pass2(e2fsck_t ctx)
        }
 
        print_resource_track(ctx, _("Pass 2"), &rtrack, fs->io);
+cleanup:
+       ext2fs_free_mem(&buf);
 }
 
 #define MAX_DEPTH 32000
index c250e31..befa832 100644 (file)
@@ -243,13 +243,16 @@ errcode_t quota_file_open(quota_ctx_t qctx, struct quota_handle *h,
                if (qctx->quota_file[qtype]) {
                        h = qctx->quota_file[qtype];
                        if (((flags & EXT2_FILE_WRITE) == 0) ||
-                           (h->qh_file_flags & EXT2_FILE_WRITE))
+                           (h->qh_file_flags & EXT2_FILE_WRITE)) {
+                               ext2fs_file_close(e2_file);
                                return 0;
+                       }
                        (void) quota_file_close(qctx, h);
                }
                err = ext2fs_get_mem(sizeof(struct quota_handle), &h);
                if (err) {
                        log_err("Unable to allocate quota handle");
+                       ext2fs_file_close(e2_file);
                        return err;
                }
                allocated_handle = 1;
index 54dd926..9f18c83 100644 (file)
@@ -632,6 +632,7 @@ write_superblock:
        retval = io_channel_write_blk64(fs->io,
                                        fs->super->s_first_data_block+1,
                                        1, buf);
+       (void) ext2fs_free_mem(&buf);
        if (retval) {
                com_err("create_journal_dev", retval, "%s",
                        _("while writing journal superblock"));
@@ -1138,7 +1139,7 @@ struct str_list {
 static errcode_t init_list(struct str_list *sl)
 {
        sl->num = 0;
-       sl->max = 0;
+       sl->max = 1;
        sl->list = malloc((sl->max+1) * sizeof(char *));
        if (!sl->list)
                return ENOMEM;
@@ -2105,6 +2106,12 @@ profile_error:
        ext2fs_blocks_count_set(&fs_param, fs_blocks_count);
 
        if (ext2fs_has_feature_journal_dev(&fs_param)) {
+               int i;
+
+               for (i=0; fs_types[i]; i++) {
+                       free(fs_types[i]);
+                       fs_types[i] = 0;
+               }
                fs_types[0] = strdup("journal");
                fs_types[1] = 0;
        }