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

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