Skip to contentSkip to conversation

btrfs-progs: zoned: fix memory leak in btrfs_sb_io()

PATCH In review Sidong Yang 4 participants 4 messages Jun 26, 2021 – Jul 1, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: zoned: fix memory leak in btrfs_sb_io()

In btrfs_sb_io(), blk_zone_report is used for getting information about zones. But it is not freed if code goes in usual path. This patch frees the variable just after it used.

---
 kernel-shared/zoned.c | 1 +
 1 file changed, 1 insertion(+)
kernel-shared/zoned.c +1 -0
index 2a6892b3..75eade84 100644
@@ -543,6 +543,7 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
 	zones = (struct blk_zone *)(rep + 1);
 
 	ret = sb_log_location(fd, zones, rw, &mapped);
+	free(rep);	
 	/*
 	 * Special case: no superblock found in the zones. This case happens
 	 * when initializing a file-system.
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Sidong Yang

In btrfs_sb_io(), blk_zone_report is used for getting information about zones. But it is not freed if code goes in usual path. This patch frees the variable just after it used.

Thanks,
Qu

Quoted 17 lines
---
  kernel-shared/zoned.c | 1 +
  1 file changed, 1 insertion(+)
kernel-shared/zoned.c +1 -0
index 2a6892b3..75eade84 100644
@@ -543,6 +543,7 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
  	zones = (struct blk_zone *)(rep + 1);
 
  	ret = sb_log_location(fd, zones, rw, &mapped);
+	free(rep);
  	/*
  	 * Special case: no superblock found in the zones. This case happens
  	 * when initializing a file-system.
Reviewed-by on v1 1/1
#2 lore raw
In reply to Sidong Yang
Quoted 5 lines · Sidong Yang

In btrfs_sb_io(), blk_zone_report is used for getting information about zones. But it is not freed if code goes in usual path. This patch frees the variable just after it used.

Thanks for catching this. Looks good.

Quoted 19 lines
---
 kernel-shared/zoned.c | 1 +
 1 file changed, 1 insertion(+)
kernel-shared/zoned.c +1 -0
index 2a6892b3..75eade84 100644
@@ -543,6 +543,7 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw)
 	zones = (struct blk_zone *)(rep + 1);
 
 	ret = sb_log_location(fd, zones, rw, &mapped);
+	free(rep);	
 	/*
 	 * Special case: no superblock found in the zones. This case happens
 	 * when initializing a file-system.
Signature · 1 line
2.25.1