!119 [sync] PR-114: xfs_db: 修复内存泄漏及代码优化

From: @openeuler-sync-bot 
Reviewed-by: @swf504 
Signed-off-by: @swf504
This commit is contained in:
openeuler-ci-bot 2024-07-12 01:45:43 +00:00 committed by Gitee
commit d7e5e75d30
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 142 additions and 1 deletions

View File

@ -0,0 +1,35 @@
From 21dc682a3842eb7e4c79f7e511d840e708d7e757 Mon Sep 17 00:00:00 2001
From: Andrey Albershteyn <aalbersh@redhat.com>
Date: Tue, 23 Apr 2024 14:36:14 +0200
Subject: xfs_db: fix leak in flist_find_ftyp()
When count is zero fl reference is lost. Fix it by freeing the list.
Fixes: a0d79cb37a36 ("xfs_db: make flist_find_ftyp() to check for field existance on disk")
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
db/flist.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/db/flist.c b/db/flist.c
index c81d229..0a6cc5f 100644
--- a/db/flist.c
+++ b/db/flist.c
@@ -424,8 +424,10 @@ flist_find_ftyp(
if (f->ftyp == type)
return fl;
count = fcount(f, obj, startoff);
- if (!count)
+ if (!count) {
+ flist_free(fl);
continue;
+ }
fa = &ftattrtab[f->ftyp];
if (fa->subfld) {
flist_t *nfl;
--
2.27.0

View File

@ -0,0 +1,101 @@
From a21daa3a739194b929de644779c359949390d467 Mon Sep 17 00:00:00 2001
From: Andrey Albershteyn <aalbersh@redhat.com>
Date: Wed, 17 Apr 2024 18:19:30 +0200
Subject: xfs_db: add helper for flist_find_type for clearer field matching
Make flist_find_type() more readable by unloading field type
matching to the helper.
Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
db/flist.c | 60 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/db/flist.c b/db/flist.c
index 0a6cc5f..ab0a0f1 100644
--- a/db/flist.c
+++ b/db/flist.c
@@ -400,6 +400,40 @@ flist_split(
return v;
}
+static flist_t *
+flist_field_match(
+ const field_t *field,
+ fldt_t type,
+ void *obj,
+ int startoff)
+{
+ flist_t *fl;
+ int count;
+ const ftattr_t *fa;
+ flist_t *nfl;
+
+ fl = flist_make(field->name);
+ fl->fld = field;
+ if (field->ftyp == type)
+ return fl;
+ count = fcount(field, obj, startoff);
+ if (!count)
+ goto out;
+ fa = &ftattrtab[field->ftyp];
+ if (!fa->subfld)
+ goto out;
+
+ nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
+ if (nfl) {
+ fl->child = nfl;
+ return fl;
+ }
+
+out:
+ flist_free(fl);
+ return NULL;
+}
+
/*
* Given a set of fields, scan for a field of the given type.
* Return an flist leading to the first found field
@@ -413,33 +447,15 @@ flist_find_ftyp(
void *obj,
int startoff)
{
- flist_t *fl;
const field_t *f;
- int count;
- const ftattr_t *fa;
+ flist_t *fl;
for (f = fields; f->name; f++) {
- fl = flist_make(f->name);
- fl->fld = f;
- if (f->ftyp == type)
+ fl = flist_field_match(f, type, obj, startoff);
+ if (fl)
return fl;
- count = fcount(f, obj, startoff);
- if (!count) {
- flist_free(fl);
- continue;
- }
- fa = &ftattrtab[f->ftyp];
- if (fa->subfld) {
- flist_t *nfl;
-
- nfl = flist_find_ftyp(fa->subfld, type, obj, startoff);
- if (nfl) {
- fl->child = nfl;
- return fl;
- }
- }
- flist_free(fl);
}
+
return NULL;
}
--
2.27.0

View File

@ -1,6 +1,6 @@
Name: xfsprogs
Version: 6.6.0
Release: 4
Release: 5
Summary: Administration and debugging tools for the XFS file system
License: GPL+ and LGPLv2+
URL: https://xfs.wiki.kernel.org
@ -22,6 +22,8 @@ Patch0: xfsprogs-5.12.0-default-bigtime-inobtcnt-on.patch
Patch1: 0001-xfsprogs-Add-sw64-architecture.patch
Patch2: 0002-xfs-fix-internal-error-from-AGFL-exhaustion.patch
Patch3: 0003-xfs_db-don-t-hardcode-type-data-size-at-512b.patch
Patch4: 0004-xfs_db-fix-leak-in-flist_find_ftyp.patch
Patch5: 0005-xfs_db-add-helper-for-flist_find_type-for-clearer-fi.patch
%description
xfsprogs are the userspace utilities that manage XFS filesystems.
@ -105,6 +107,9 @@ rm -rf %{buildroot}%{_datadir}/doc/xfsprogs/
%changelog
* Tue Jun 4 2024 liuh <liuhuan01@kylinos.cn> - 6.6.0-5
- sync patches from community
* Wed May 08 2024 chendexi <chendexi@kylinos.cn> - 6.6.0-4
- Remove xfs_scrub related files from the main package to remove python dependencies