From 829aad36dbbeee462fa142fe2c571fd7ab735ba8 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 26 Jun 2023 17:09:08 -0400
Subject: [PATCH] backport part of patch to fix small memleak in globbing

Conflict:backport part of patch to fix small memleak in globbing
Reference:https://git.savannah.gnu.org/cgit/bash.git/commit/?id=829aad36dbbeee462fa142fe2c571fd7ab735ba8
---
 lib/glob/glob.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/glob/glob.c b/lib/glob/glob.c
index eb6277f..6475814 100644
--- a/lib/glob/glob.c
+++ b/lib/glob/glob.c
@@ -1392,6 +1392,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

