Skip to content

Commit

Permalink
ext4: call ext4_ext_drop_refs() from ext4_ext_find_extent()
Browse files Browse the repository at this point in the history
In nearly all of the calls to ext4_ext_find_extent() where the caller
is trying to recycle the path object, ext4_ext_drop_refs() gets called
to release the buffer heads before the path object gets overwritten.
To simplify things for the callers, and to avoid the possibility of a
memory leak, make ext4_ext_find_extent() responsible for dropping the
buffers.

Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Sep 1, 2014
1 parent dfe5080 commit 523f431
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions fs/ext4/extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,10 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
eh = ext_inode_hdr(inode);
depth = ext_depth(inode);

/* account possible depth increase */
if (!path) {
if (path)
ext4_ext_drop_refs(path);
else {
/* account possible depth increase */
path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 2),
GFP_NOFS);
if (unlikely(!path))
Expand Down Expand Up @@ -1356,7 +1358,6 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
goto out;

/* refill path */
ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode,
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
ppath, gb_flags);
Expand All @@ -1369,7 +1370,6 @@ static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode,
goto out;

/* refill path */
ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode,
(ext4_lblk_t)le32_to_cpu(newext->ee_block),
ppath, gb_flags);
Expand Down Expand Up @@ -3319,7 +3319,6 @@ static int ext4_split_extent(handle_t *handle,
* Update path is required because previous ext4_split_extent_at() may
* result in split of original leaf or extent zeroout.
*/
ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
if (IS_ERR(path))
return PTR_ERR(path);
Expand Down Expand Up @@ -3718,7 +3717,6 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
EXT4_GET_BLOCKS_CONVERT);
if (err < 0)
return err;
ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
if (IS_ERR(path))
return PTR_ERR(path);
Expand Down Expand Up @@ -3947,7 +3945,6 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,
EXT4_GET_BLOCKS_CONVERT_UNWRITTEN);
if (err < 0)
return err;
ext4_ext_drop_refs(path);
path = ext4_ext_find_extent(inode, map->m_lblk, ppath, 0);
if (IS_ERR(path))
return PTR_ERR(path);
Expand Down

0 comments on commit 523f431

Please sign in to comment.