Coverity reports this:
*** CID 1666510: Resource leaks (RESOURCE_LEAK)
/gllib/glob.c: 876 in rpl_glob()
870 {
871 if (flags & GLOB_TILDE_CHECK)
872 {
873 /* We have to regard it as an error if we cannot
find the
874 home directory. */
875 retval = GLOB_NOMATCH;
>>> CID 1666510: Resource leaks (RESOURCE_LEAK)
>>> Variable "pwtmpbuf" going out of scope leaks the storage "pwtmpbuf.data"
>>> points to.
876 goto out;
877 }
878 }
879 scratch_buffer_free (&pwtmpbuf);
880 }
881 #else /* WINDOWS32 */
This patch should fix it.
Collin, feel free to port this fix to glibc.
2025-10-21 Bruno Haible <[email protected]>
glob: Fix a memory leak.
Found by Coverity.
* lib/glob.c (__glob): Add scratch_buffer_free invocation, to match
scratch_buffer_init invocation.
diff --git a/lib/glob.c b/lib/glob.c
index 48f10ae0e1..dc21014aff 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -872,6 +872,7 @@ __glob (const char *pattern, int flags, int (*errfunc)
(const char *, int),
{
/* We have to regard it as an error if we cannot find the
home directory. */
+ scratch_buffer_free (&pwtmpbuf);
retval = GLOB_NOMATCH;
goto out;
}