Skip to content

Commit

Permalink
libf2fs: Fix possible memleak with Sparse Files
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
drosen-google authored and Jaegeuk Kim committed Jan 29, 2024
1 parent 9f435e3 commit eca9049
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/libf2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit eca9049

Please sign in to comment.