[PATCH 3/6] posix: Use malloc instead of alloca for the glob user name

Adhemerval Zanella <[email protected]> Mon, 3 Aug 2026 16:19:17 -0300
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
Use malloc unconditionally.  The name is only needed for the passwd
lookup that follows, which is far more expensive than the allocation.

Checked on x86_64-linux-gnu, aarch64-linux-gnu, and i686-linux-gnu.
---
 posix/glob.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/posix/glob.c b/posix/glob.c
index 1b1fd8eda02..a9d69dde24a 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -826,19 +826,13 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
             user_name = dirname + 1;
           else
             {
-              char *newp;
-              if (glob_use_alloca (alloca_used, end_name - dirname))
-                newp = alloca_account (end_name - dirname, alloca_used);
-              else
+              char *newp = malloc (end_name - dirname);
+              if (newp == NULL)
                 {
-                  newp = malloc (end_name - dirname);
-                  if (newp == NULL)
-                    {
-                      retval = GLOB_NOSPACE;
-                      goto out;
-                    }
-                  malloc_user_name = 1;
+                  retval = GLOB_NOSPACE;
+                  goto out;
                 }
+              malloc_user_name = 1;
               if (unescape != NULL)
                 {
                   char *p = mempcpy (newp, dirname + 1,
-- 
2.53.0