From 81fa0c0f30bb6bcd2a4d287748db6d090b0d04ea Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 22 Nov 2023 13:35:55 -0800 Subject: glob: suppress consecutive duplicates; fix memleak. * glob.c (glob_wrap): When converting the glob array to the returned list, suppress consecutive duplicates. This has to be done separately for each call to glob or super_glob, so we now interleave the production of the output list with the glob calls. It has to be done separately because there can be duplicates between different patterns. E.g. if (glob "?") matches one path then (glob '("?" "?")) must return two copies of it. Furthermore, the brace expansion implementation in glob* produces multiple glob calls and appends their results. Duplicates inside a single super_glob call result when there are multiple ** (double star) patterns present, which are matched by the same path in more than one way. If the results are sorted, then the duplicates appear consecutively and we will squash them. Also, a memory leak is fixed here: we must free(pat_u8) unconditionally, before testing for the early exit situation. --- tests/018/glob.tl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/018/glob.tl b/tests/018/glob.tl index f28ec480..438e4c65 100644 --- a/tests/018/glob.tl +++ b/tests/018/glob.tl @@ -112,7 +112,7 @@ (glob* "**/{3,4,5}*/**" glob-xnobrace) nil (len (glob* "**/proc/**/**")) - 547) + 366) (if (neq (os-symbol) :solaris) (test -- cgit v1.2.3