diff mbox series

[f2fs-dev,2/2] libf2fs: Fix possible memleak with Sparse Files

Message ID 20240126221845.265859-2-drosen@google.com (mailing list archive)
State New
Headers show
Series [f2fs-dev,1/2] libf2fs: Accept Sparse files with non 4K Blocksize | expand

Commit Message

Daniel Rosenberg Jan. 26, 2024, 10:18 p.m. UTC
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>
---
 lib/libf2fs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;
 }