bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] fix compgen -V leak


From: Grisha Levit
Subject: [PATCH] fix compgen -V leak
Date: Sat, 17 Jun 2023 02:49:57 -0400

My earlier patch for adding compgen -V did the variable assignment in a
pretty silly way and had a small memory leak to boot. Hope this new way
makes sense, sorry for the extra work.
---
>From b6b13b89e1436ddd575483a81e79ef43d82a5c0c Mon Sep 17 00:00:00 2001
From: Grisha Levit <grishalevit@gmail.com>
Date: Sat, 3 Jun 2023 16:37:02 -0400
Subject: [PATCH] fixup compgen -V array handling

* builtins/complete.def
- compgen_builtin: skip the unnecessary WORD_LIST conversion, avoid
  small leak

* externs.h
- remove strlist_to_word_list which was only added for initial version
  of compgen -V support
---
 builtins/complete.def | 7 +------
 externs.h             | 1 -
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/builtins/complete.def b/builtins/complete.def
index 890cf20d..bb03c6e9 100644
--- a/builtins/complete.def
+++ b/builtins/complete.def
@@ -678,7 +678,6 @@ compgen_builtin (WORD_LIST *list)
   int old_ind, old_completion, old_quoting, old_suppress;
   SHELL_VAR *var;
   char *varname;
-  WORD_LIST *alist;

   if (list == 0)
     return (EXECUTION_SUCCESS);
@@ -763,11 +762,7 @@ compgen_builtin (WORD_LIST *list)
       var = builtin_find_indexed_array (varname, 1);
       if (var && sl && sl->list && sl->list_len)
  {
-   alist = strlist_to_word_list (sl, 0, 0);
-   assign_array_var_from_word_list (var, alist, 0);
-   free (sl);
-   sl = (STRINGLIST *)NULL;
-   dispose_words (alist);
+   array_from_argv (array_cell(var), sl->list, sl->list_len);
    rval = EXECUTION_SUCCESS;
  }
     }
diff --git a/externs.h b/externs.h
index a1363d4d..fe5aa492 100644
--- a/externs.h
+++ b/externs.h
@@ -414,7 +414,6 @@ extern STRINGLIST *strlist_prefix_suffix (STRINGLIST *,
const char *, const char
 extern void strlist_print (STRINGLIST *, const char *);
 extern void strlist_walk (STRINGLIST *, sh_strlist_map_func_t *);
 extern void strlist_sort (STRINGLIST *);
-extern WORD_LIST *strlist_to_word_list (STRINGLIST *, int, int);

 /* declarations for functions defined in lib/sh/stringvec.c */

-- 
2.41.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]