diff options
author | Daniel Rosenberg <drosen@google.com> | 2024-01-26 14:18:45 -0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2024-01-29 12:14:56 -0800 |
commit | eca9049a079251a65120cd0dd91d5056a3d44360 (patch) | |
tree | 18721aa6a0d52b63674df3aa9b610d8f77547983 | |
parent | 9f435e3d57d3ab478d37ce0398ae9095425a48df (diff) | |
download | f2fs-tools-eca9049a079251a65120cd0dd91d5056a3d44360.tar.gz |
libf2fs: Fix possible memleak with Sparse Files
If sparse files is set along with multiple devices, we initialize
sparse file data multiple times without freeing the previously allocated
data. This skips the initialization for subsequent devices, as sparse
file mode currently only deals with device 0 anyways.
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | lib/libf2fs.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 2451201..13f2b07 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -974,7 +974,7 @@ int get_device_info(int i) dev->fd = fd; - if (c.sparse_mode) { + if (c.sparse_mode && i == 0) { if (f2fs_init_sparse_file()) { free(stat_buf); return -1; @@ -1221,7 +1221,7 @@ int get_device_info(int i) c.sectors_per_blk = F2FS_BLKSIZE / c.sector_size; c.total_sectors += dev->total_sectors; - if (c.sparse_mode && f2fs_init_sparse_file()) + if (c.sparse_mode && i==0 && f2fs_init_sparse_file()) return -1; return 0; } |