ext4: Fix memory and buffer head leak in callers to ext4_ext_find_extent()

The path variable returned via ext4_ext_find_extent is a kmalloc
variable and needs to be freeded.  It also contains a reference to
buffer_head which needs to be dropped.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Aneesh Kumar K.V 2008-02-25 16:54:37 -05:00 committed by Theodore Ts'o
parent 4cdeed861b
commit b35905c16a
3 changed files with 9 additions and 3 deletions

View File

@ -349,7 +349,7 @@ static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path)
#define ext4_ext_show_leaf(inode,path) #define ext4_ext_show_leaf(inode,path)
#endif #endif
static void ext4_ext_drop_refs(struct ext4_ext_path *path) void ext4_ext_drop_refs(struct ext4_ext_path *path)
{ {
int depth = path->p_depth; int depth = path->p_depth;
int i; int i;
@ -2200,10 +2200,10 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
newdepth = ext_depth(inode); newdepth = ext_depth(inode);
if (newdepth != depth) { if (newdepth != depth) {
depth = newdepth; depth = newdepth;
path = ext4_ext_find_extent(inode, iblock, NULL); ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode, iblock, path);
if (IS_ERR(path)) { if (IS_ERR(path)) {
err = PTR_ERR(path); err = PTR_ERR(path);
path = NULL;
goto out; goto out;
} }
eh = path[depth].p_hdr; eh = path[depth].p_hdr;

View File

@ -43,6 +43,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
if (IS_ERR(path)) { if (IS_ERR(path)) {
retval = PTR_ERR(path); retval = PTR_ERR(path);
path = NULL;
goto err_out; goto err_out;
} }
@ -74,6 +75,10 @@ static int finish_range(handle_t *handle, struct inode *inode,
} }
retval = ext4_ext_insert_extent(handle, inode, path, &newext); retval = ext4_ext_insert_extent(handle, inode, path, &newext);
err_out: err_out:
if (path) {
ext4_ext_drop_refs(path);
kfree(path);
}
lb->first_pblock = 0; lb->first_pblock = 0;
return retval; return retval;
} }

View File

@ -227,5 +227,6 @@ extern int ext4_ext_search_left(struct inode *, struct ext4_ext_path *,
ext4_lblk_t *, ext4_fsblk_t *); ext4_lblk_t *, ext4_fsblk_t *);
extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *, extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *,
ext4_lblk_t *, ext4_fsblk_t *); ext4_lblk_t *, ext4_fsblk_t *);
extern void ext4_ext_drop_refs(struct ext4_ext_path *);
#endif /* _LINUX_EXT4_EXTENTS */ #endif /* _LINUX_EXT4_EXTENTS */