From 1512dc33b36ad0feff9dbdcfe38e6d2acdcb38a0 Mon Sep 17 00:00:00 2001 From: Li Jinlin Date: Tue, 29 Mar 2022 11:10:19 +0800 Subject: [PATCH 6/6] fat_clobber: set boot_sector = NULL and free boot_sector after failed of fat_boot_sector_read When fat_boot_sector_read() returns failure, boot_sector may have allocated memory, and memory leak will occur Signed-off-by: Wu Guanghao Signed-off-by: Li Jinlin --- 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