Skip to content

Commit

Permalink
[PATCH] hfs, hfsplus: don't leak s_fs_info and fix an oops
Browse files Browse the repository at this point in the history
This patch fixes the leak of sb->s_fs_info in both the HFS and HFS+
modules.  In addition to this, it fixes an oops happening when trying to
mount a non-hfsplus filesystem using hfsplus.  This patch is from Roman
Zippel, based off patches sent by myself.

Signed-off-by: Colin Leroy <colin@colino.net>
Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Colin Leroy authored and Linus Torvalds committed May 1, 2005
1 parent 954d3e9 commit 945b092
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions fs/hfs/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,16 @@ void hfs_mdb_close(struct super_block *sb)
* Release the resources associated with the in-core MDB. */
void hfs_mdb_put(struct super_block *sb)
{
if (!HFS_SB(sb))
return;
/* free the B-trees */
hfs_btree_close(HFS_SB(sb)->ext_tree);
hfs_btree_close(HFS_SB(sb)->cat_tree);

/* free the buffers holding the primary and alternate MDBs */
brelse(HFS_SB(sb)->mdb_bh);
brelse(HFS_SB(sb)->alt_mdb_bh);

kfree(HFS_SB(sb));
sb->s_fs_info = NULL;
}
8 changes: 3 additions & 5 deletions fs/hfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
res = -EINVAL;
if (!parse_options((char *)data, sbi)) {
hfs_warn("hfs_fs: unable to parse mount options.\n");
goto bail3;
goto bail;
}

sb->s_op = &hfs_super_operations;
Expand All @@ -310,7 +310,7 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
hfs_warn("VFS: Can't find a HFS filesystem on dev %s.\n",
hfs_mdb_name(sb));
res = -EINVAL;
goto bail2;
goto bail;
}

/* try to get the root inode */
Expand Down Expand Up @@ -340,10 +340,8 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
iput(root_inode);
bail_no_root:
hfs_warn("hfs_fs: get root inode failed.\n");
bail:
hfs_mdb_put(sb);
bail2:
bail3:
kfree(sbi);
return res;
}

Expand Down
6 changes: 5 additions & 1 deletion fs/hfsplus/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ static void hfsplus_write_super(struct super_block *sb)
static void hfsplus_put_super(struct super_block *sb)
{
dprint(DBG_SUPER, "hfsplus_put_super\n");
if (!(sb->s_flags & MS_RDONLY)) {
if (!sb->s_fs_info)
return;
if (!(sb->s_flags & MS_RDONLY) && HFSPLUS_SB(sb).s_vhdr) {
struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;

vhdr->modify_date = hfsp_now2mt();
Expand All @@ -226,6 +228,8 @@ static void hfsplus_put_super(struct super_block *sb)
brelse(HFSPLUS_SB(sb).s_vhbh);
if (HFSPLUS_SB(sb).nls)
unload_nls(HFSPLUS_SB(sb).nls);
kfree(sb->s_fs_info);
sb->s_fs_info = NULL;
}

static int hfsplus_statfs(struct super_block *sb, struct kstatfs *buf)
Expand Down

0 comments on commit 945b092

Please sign in to comment.