From 707fbd56f11e79bc30080f67eeff2b1b71e08b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 28 Aug 2017 09:30:24 +0200 Subject: [PATCH] Fix memory leaks when running quotacheck on ext file systems --- ...llocate-memory-after-direct-scanning.patch | 99 +++++++++++++++++++ quota.spec | 9 +- 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch diff --git a/quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch b/quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch new file mode 100644 index 0000000..ee02d7b --- /dev/null +++ b/quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch @@ -0,0 +1,99 @@ +From bf9b17da317ecf56ceada3a575fb95669bf2041b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Mon, 21 Aug 2017 13:02:21 +0200 +Subject: [PATCH] quotacheck: Deallocate memory after direct scanning +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +quotacheck had memory leaks because it did not clean up after direct +ext scanning: + +==6885== 1,392 (88 direct, 1,304 indirect) bytes in 1 blocks are definitely lost in loss record 19 of 23 +==6885== at 0x4C29BE3: malloc (vg_replace_malloc.c:299) +==6885== by 0x4E5288B: ext2fs_make_generic_bitmap (in /usr/lib64/libext2fs.so.2.4) +==6885== by 0x4E47ED5: ext2fs_allocate_inode_bitmap (in /usr/lib64/libext2fs.so.2.4) +==6885== by 0x10BBA5: ext2_direct_scan (quotacheck.c:435) +==6885== by 0x10DA8A: check_dir (quotacheck.c:971) +==6885== by 0x10E634: check_all (quotacheck.c:1192) +==6885== by 0x10E6EC: main (quotacheck.c:1212) +==6885== +==6885== 8,464 (144 direct, 8,320 indirect) bytes in 1 blocks are definitely lost in loss record 22 of 23 +==6885== at 0x4C29BE3: malloc (vg_replace_malloc.c:299) +==6885== by 0x4E5749D: ext2fs_open_inode_scan (in /usr/lib64/libext2fs.so.2.4) +==6885== by 0x10BBF0: ext2_direct_scan (quotacheck.c:440) +==6885== by 0x10DA8A: check_dir (quotacheck.c:971) +==6885== by 0x10E634: check_all (quotacheck.c:1192) +==6885== by 0x10E6EC: main (quotacheck.c:1212) +==6885== +==6885== 15,243 (88 direct, 15,155 indirect) bytes in 1 blocks are definitely lost in loss record 23 of 23 +==6885== at 0x4C29BE3: malloc (vg_replace_malloc.c:299) +==6885== by 0x4E5288B: ext2fs_make_generic_bitmap (in /usr/lib64/libext2fs.so.2.4) +==6885== by 0x4E47ED5: ext2fs_allocate_inode_bitmap (in /usr/lib64/libext2fs.so.2.4) +==6885== by 0x10BB55: ext2_direct_scan (quotacheck.c:430) +==6885== by 0x10DA8A: check_dir (quotacheck.c:971) +==6885== by 0x10E634: check_all (quotacheck.c:1192) +==6885== by 0x10E6EC: main (quotacheck.c:1212) + +Signed-off-by: Petr Písař +--- + quotacheck.c | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) + +diff --git a/quotacheck.c b/quotacheck.c +index 689ceb9..e9a84ba 100644 +--- a/quotacheck.c ++++ b/quotacheck.c +@@ -429,21 +429,31 @@ static int ext2_direct_scan(const char *device) + + if ((error = ext2fs_allocate_inode_bitmap(fs, "in-use inode map", &inode_used_map))) { + errstr(_("error (%d) while allocating file inode bitmap\n"), (int)error); ++ ext2fs_free(fs); + return -1; + } + + if ((error = ext2fs_allocate_inode_bitmap(fs, "directory inode map", &inode_dir_map))) { + errstr(_("errstr (%d) while allocating directory inode bitmap\n"), (int)error); ++ ext2fs_free_inode_bitmap(inode_used_map); ++ ext2fs_free(fs); + return -1; + } + + if ((error = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan))) { + errstr(_("error (%d) while opening inode scan\n"), (int)error); ++ ext2fs_free_inode_bitmap(inode_dir_map); ++ ext2fs_free_inode_bitmap(inode_used_map); ++ ext2fs_free(fs); + return -1; + } + + if ((error = ext2fs_get_next_inode(scan, &i_num, &inode))) { + errstr(_("error (%d) while starting inode scan\n"), (int)error); ++ ext2fs_close_inode_scan(scan); ++ ext2fs_free_inode_bitmap(inode_dir_map); ++ ext2fs_free_inode_bitmap(inode_used_map); ++ ext2fs_free(fs); + return -1; + } + +@@ -474,9 +484,17 @@ static int ext2_direct_scan(const char *device) + + if ((error = ext2fs_get_next_inode(scan, &i_num, &inode))) { + errstr(_("Something weird happened while scanning. Error %d\n"), (int)error); ++ ext2fs_close_inode_scan(scan); ++ ext2fs_free_inode_bitmap(inode_dir_map); ++ ext2fs_free_inode_bitmap(inode_used_map); ++ ext2fs_free(fs); + return -1; + } + } ++ ext2fs_close_inode_scan(scan); ++ ext2fs_free_inode_bitmap(inode_dir_map); ++ ext2fs_free_inode_bitmap(inode_used_map); ++ ext2fs_free(fs); + return 0; + } + #endif +-- +2.9.5 + diff --git a/quota.spec b/quota.spec index 6cbf2f1..7d01dff 100644 --- a/quota.spec +++ b/quota.spec @@ -6,7 +6,7 @@ Name: quota Epoch: 1 Version: 4.03 -Release: 11%{?dist} +Release: 12%{?dist} Group: System Environment/Base Summary: System administration tools for monitoring users' disk usage # quota_nld.c, quotaio_xfs.h: GPLv2 @@ -77,6 +77,9 @@ Patch14: quota-4.03-quotaops-check-setgid-setuid-return-code.patch Patch15: quota-4.03-quotaops-check-return-code-of-fgets-calls.patch # Check for failures when duplicating a file handle, in upstream after 4.03 Patch16: quota-4.03-quotaops-check-return-code-of-ftruncate-and-lseek-ca.patch +# Fix memory leaks when running quotacheck on ext file systems, bug #1483543, +# +Patch17: quota-4.03-quotacheck-Deallocate-memory-after-direct-scanning.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: bash @@ -205,6 +208,7 @@ Linux/UNIX environment. %patch14 -p1 %patch15 -p1 %patch16 -p1 +%patch17 -p1 # Unpack forgotten LDAP scripts tar -xzkf %{SOURCE5} # Regenerate build scripts, also because of Respect-enviroment-CFLAGS.patch @@ -331,6 +335,9 @@ make check %changelog +* Mon Aug 28 2017 Petr Pisar - 1:4.03-12 +- Fix memory leaks when running quotacheck on ext file systems (bug #1483543) + * Thu Aug 03 2017 Fedora Release Engineering - 1:4.03-11 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild