Blame SOURCES/quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch

370c56
From bf9b17da317ecf56ceada3a575fb95669bf2041b Mon Sep 17 00:00:00 2001
370c56
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
370c56
Date: Mon, 21 Aug 2017 13:02:21 +0200
370c56
Subject: [PATCH] quotacheck: Deallocate memory after direct scanning
370c56
MIME-Version: 1.0
370c56
Content-Type: text/plain; charset=UTF-8
370c56
Content-Transfer-Encoding: 8bit
370c56
370c56
quotacheck had memory leaks because it did not clean up after direct
370c56
ext scanning:
370c56
370c56
==6885== 1,392 (88 direct, 1,304 indirect) bytes in 1 blocks are definitely lost in loss record 19 of 23
370c56
==6885==    at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
370c56
==6885==    by 0x4E5288B: ext2fs_make_generic_bitmap (in /usr/lib64/libext2fs.so.2.4)
370c56
==6885==    by 0x4E47ED5: ext2fs_allocate_inode_bitmap (in /usr/lib64/libext2fs.so.2.4)
370c56
==6885==    by 0x10BBA5: ext2_direct_scan (quotacheck.c:435)
370c56
==6885==    by 0x10DA8A: check_dir (quotacheck.c:971)
370c56
==6885==    by 0x10E634: check_all (quotacheck.c:1192)
370c56
==6885==    by 0x10E6EC: main (quotacheck.c:1212)
370c56
==6885==
370c56
==6885== 8,464 (144 direct, 8,320 indirect) bytes in 1 blocks are definitely lost in loss record 22 of 23
370c56
==6885==    at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
370c56
==6885==    by 0x4E5749D: ext2fs_open_inode_scan (in /usr/lib64/libext2fs.so.2.4)
370c56
==6885==    by 0x10BBF0: ext2_direct_scan (quotacheck.c:440)
370c56
==6885==    by 0x10DA8A: check_dir (quotacheck.c:971)
370c56
==6885==    by 0x10E634: check_all (quotacheck.c:1192)
370c56
==6885==    by 0x10E6EC: main (quotacheck.c:1212)
370c56
==6885==
370c56
==6885== 15,243 (88 direct, 15,155 indirect) bytes in 1 blocks are definitely lost in loss record 23 of 23
370c56
==6885==    at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
370c56
==6885==    by 0x4E5288B: ext2fs_make_generic_bitmap (in /usr/lib64/libext2fs.so.2.4)
370c56
==6885==    by 0x4E47ED5: ext2fs_allocate_inode_bitmap (in /usr/lib64/libext2fs.so.2.4)
370c56
==6885==    by 0x10BB55: ext2_direct_scan (quotacheck.c:430)
370c56
==6885==    by 0x10DA8A: check_dir (quotacheck.c:971)
370c56
==6885==    by 0x10E634: check_all (quotacheck.c:1192)
370c56
==6885==    by 0x10E6EC: main (quotacheck.c:1212)
370c56
370c56
Signed-off-by: Petr Písař <ppisar@redhat.com>
370c56
---
370c56
 quotacheck.c | 18 ++++++++++++++++++
370c56
 1 file changed, 18 insertions(+)
370c56
370c56
diff --git a/quotacheck.c b/quotacheck.c
370c56
index 689ceb9..e9a84ba 100644
370c56
--- a/quotacheck.c
370c56
+++ b/quotacheck.c
370c56
@@ -429,21 +429,31 @@ static int ext2_direct_scan(const char *device)
370c56
 
370c56
 	if ((error = ext2fs_allocate_inode_bitmap(fs, "in-use inode map", &inode_used_map))) {
370c56
 		errstr(_("error (%d) while allocating file inode bitmap\n"), (int)error);
370c56
+		ext2fs_free(fs);
370c56
 		return -1;
370c56
 	}
370c56
 
370c56
 	if ((error = ext2fs_allocate_inode_bitmap(fs, "directory inode map", &inode_dir_map))) {
370c56
 		errstr(_("errstr (%d) while allocating directory inode bitmap\n"), (int)error);
370c56
+		ext2fs_free_inode_bitmap(inode_used_map);
370c56
+		ext2fs_free(fs);
370c56
 		return -1;
370c56
 	}
370c56
 
370c56
 	if ((error = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan))) {
370c56
 		errstr(_("error (%d) while opening inode scan\n"), (int)error);
370c56
+		ext2fs_free_inode_bitmap(inode_dir_map);
370c56
+		ext2fs_free_inode_bitmap(inode_used_map);
370c56
+		ext2fs_free(fs);
370c56
 		return -1;
370c56
 	}
370c56
 
370c56
 	if ((error = ext2fs_get_next_inode(scan, &i_num, &inode))) {
370c56
 		errstr(_("error (%d) while starting inode scan\n"), (int)error);
370c56
+		ext2fs_close_inode_scan(scan);
370c56
+		ext2fs_free_inode_bitmap(inode_dir_map);
370c56
+		ext2fs_free_inode_bitmap(inode_used_map);
370c56
+		ext2fs_free(fs);
370c56
 		return -1;
370c56
 	}
370c56
 
370c56
@@ -474,9 +484,17 @@ static int ext2_direct_scan(const char *device)
370c56
 
370c56
 		if ((error = ext2fs_get_next_inode(scan, &i_num, &inode))) {
370c56
 			errstr(_("Something weird happened while scanning. Error %d\n"), (int)error);
370c56
+			ext2fs_close_inode_scan(scan);
370c56
+			ext2fs_free_inode_bitmap(inode_dir_map);
370c56
+			ext2fs_free_inode_bitmap(inode_used_map);
370c56
+			ext2fs_free(fs);
370c56
 			return -1;
370c56
 		}
370c56
 	}
370c56
+	ext2fs_close_inode_scan(scan);
370c56
+	ext2fs_free_inode_bitmap(inode_dir_map);
370c56
+	ext2fs_free_inode_bitmap(inode_used_map);
370c56
+	ext2fs_free(fs);
370c56
 	return 0;
370c56
 }
370c56
 #endif
370c56
-- 
370c56
2.9.5
370c56