[parted-devel] [PATCH 6/6] fat_clobber: set boot_sector = NULL and free boot_sector after failed of fat_boot_sector_read
Wu Guanghao
wuguanghao3 at huawei.com
Wed Dec 15 08:30:04 GMT 2021
When fat_boot_sector_read() returns failure, boot_sector may have
allocated memory, and memory leak will occur
Signed-off-by: Wu Guanghao <wuguanghao3 at huawei.com>
---
libparted/fs/r/fat/fat.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libparted/fs/r/fat/fat.c b/libparted/fs/r/fat/fat.c
index 396494a..33a4284 100644
--- a/libparted/fs/r/fat/fat.c
+++ b/libparted/fs/r/fat/fat.c
@@ -117,11 +117,13 @@ fat_set_frag_sectors (PedFileSystem* fs, PedSector frag_sectors)
int
fat_clobber (PedGeometry* geom)
{
- FatBootSector *boot_sector;
+ FatBootSector *boot_sector = NULL;
int ok;
- if (!fat_boot_sector_read (&boot_sector, geom))
+ if (!fat_boot_sector_read (&boot_sector, geom)) {
+ free(boot_sector);
return 1;
+ }
boot_sector->system_id[0] = 0;
boot_sector->boot_sign = 0;
--
2.27.0
More information about the parted-devel
mailing list