f2fs: fix a problem of using memory after free
authorYunlei He <heyunlei@huawei.com>
Mon, 19 Dec 2016 12:10:48 +0000 (20:10 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 29 Jan 2017 03:46:01 +0000 (12:46 +0900)
This patch fix a problem of using memory after free
in function __try_merge_extent_node.

Fixes: 0f825ee6e873 ("f2fs: add new interfaces for extent tree")
Cc: <stable@vger.kernel.org>
Signed-off-by: Yunlei He <heyunlei@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/extent_cache.c

index 4db44da7ef69d1d4bb7be862d8266508c58a4793..e02c3d88dc9a27375ee85c36d8df4c01b29a376c 100644 (file)
@@ -352,11 +352,12 @@ static struct extent_node *__try_merge_extent_node(struct inode *inode,
        }
 
        if (next_ex && __is_front_mergeable(ei, &next_ex->ei)) {
-               if (en)
-                       __release_extent_node(sbi, et, prev_ex);
                next_ex->ei.fofs = ei->fofs;
                next_ex->ei.blk = ei->blk;
                next_ex->ei.len += ei->len;
+               if (en)
+                       __release_extent_node(sbi, et, prev_ex);
+
                en = next_ex;
        }