From 829aad36dbbeee462fa142fe2c571fd7ab735ba8 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Mon, 26 Jun 2023 17:09:08 -0400 Subject: [PATCH] backport part of patch to fix small memleak in globbing --- lib/glob/glob.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/glob/glob.c b/lib/glob/glob.c index b66af85..e4283bd 100644 --- a/lib/glob/glob.c +++ b/lib/glob/glob.c @@ -1446,6 +1446,12 @@ glob_filename (pathname, flags) free ((char *) array); else if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0') free (temp_results); /* expanding ** case above */ + else if (array == temp_results) + /* If array == temp_results, either we assigned it above or + glob_dir_to_array returned temp_results because the dirname + was the empty string. In any case, we assume temp_results + has not been freed, and free it here. */ + free (temp_results); if (shouldbreak) break; -- 2.33.0