I found this by accident and then reproduce it through artificial mem pressure
test.
And I update the patch as you said.
*lib/fts.c:return when malloc failed in function setup_dir()
---
lib/fts.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/fts.c b/lib/fts.c
index 78584b2902..c2fa5ee8dc 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -979,7 +979,11 @@ next: tmp = p;
}
free_dir(sp);
fts_load(sp, p);
- setup_dir(sp);
+ if (! setup_dir(sp)) {
+ free_dir(sp);
+ __set_errno (ENOMEM);
+ return (NULL);
+ }
goto check_for_dir;
}