]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0341: Problem: a few memory leaks are found v9.1.0341
authorChristian Brabandt <cb@256bit.org>
Tue, 16 Apr 2024 20:44:31 +0000 (22:44 +0200)
committerChristian Brabandt <cb@256bit.org>
Tue, 16 Apr 2024 20:44:31 +0000 (22:44 +0200)
Problem:  a few memory leaks are found
          (LuMingYinDetect )
Solution: properly free the memory

Fixes the following problems:
- Memory leak in f_maplist()
  fixes: #14486

- Memory leak in option.c
  fixes: #14485

- Memory leak in f_resolve()
  fixes: #14484

- Memory leak in f_autocmd_get()
  related: #14474

- Memory leak in dict_extend_func()
  fixes: #14477
  fixes: #14238

closes: #14517

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/autocmd.c
src/dict.c
src/filepath.c
src/map.c
src/option.c
src/testdir/test_listdict.vim
src/version.c

index 666cf45d3033ab339cdb0f11fb25eec38463f5c8..bce57cb759e06299a5b9e5f1ab0c761a65667902 100644 (file)
@@ -3406,7 +3406,10 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
                event_dict = dict_alloc();
                if (event_dict == NULL
                        || list_append_dict(event_list, event_dict) == FAIL)
+               {
+                   vim_free(pat);
                    return;
+               }
 
                if (dict_add_string(event_dict, "event", event_name) == FAIL
                        || dict_add_string(event_dict, "group",
@@ -3421,7 +3424,10 @@ f_autocmd_get(typval_T *argvars, typval_T *rettv)
                        || dict_add_bool(event_dict, "once", ac->once) == FAIL
                        || dict_add_bool(event_dict, "nested",
                                                           ac->nested) == FAIL)
+               {
+                   vim_free(pat);
                    return;
+               }
            }
        }
     }
index 508d00cdf7c402afb1e4e2f16f0c7374c2f23528..c78995d80e51d6d87d4673a982d556b1a20b00e8 100644 (file)
@@ -1300,12 +1300,18 @@ dict_extend_func(
 
        action = tv_get_string_chk(&argvars[2]);
        if (action == NULL)
+       {
+           if (is_new)
+               dict_unref(d1);
            return;
+       }
        for (i = 0; i < 3; ++i)
            if (STRCMP(action, av[i]) == 0)
                break;
        if (i == 3)
        {
+           if (is_new)
+               dict_unref(d1);
            semsg(_(e_invalid_argument_str), action);
            return;
        }
index cbf2da41360bd781b4a7b7fbf074fa136c197323..3bf8a2d269e71ff9cd31e8051924f40657324ae3 100644 (file)
@@ -2110,6 +2110,7 @@ f_resolve(typval_T *argvars, typval_T *rettv)
        if (buf == NULL)
        {
            vim_free(p);
+           vim_free(remain);
            goto fail;
        }
 
index b7bb46c047f3d9a5c13b54af2d548bf4b5b646c1..c416c0a32777d10301f9026527f6f255c8f3dc56 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -2574,7 +2574,10 @@ f_maplist(typval_T *argvars UNUSED, typval_T *rettv)
                if ((d = dict_alloc()) == NULL)
                    return;
                if (list_append_dict(rettv->vval.v_list, d) == FAIL)
+               {
+                   dict_unref(d);
                    return;
+               }
 
                keys_buf = NULL;
                did_simplify = FALSE;
index f0fca6f45c5b2b6e8da7fe9a58728a1af4c9f1f8..1bb9e29baeaf4f2ae033c231b809763bc73d6414 100644 (file)
@@ -853,7 +853,10 @@ set_string_default_esc(char *name, char_u *val, int escape)
 
     opt_idx = findoption((char_u *)name);
     if (opt_idx < 0)
+    {
+       vim_free(p);
        return;
+    }
 
     if (options[opt_idx].flags & P_DEF_ALLOCED)
        vim_free(options[opt_idx].def_val[VI_DEFAULT]);
index 8b2c27a89f8509f48989fa92afeb5b05b812bacd..4c694763620e08f847e5607ae42f644fb198b5ba 100644 (file)
@@ -1530,4 +1530,10 @@ func Test_indexof()
   delfunc TestIdx
 endfunc
 
+func Test_extendnew_leak()
+  " This used to leak memory
+  for i in range(100) | silent! call extendnew([], [], []) | endfor
+  for i in range(100) | silent! call extendnew({}, {}, {}) | endfor
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 56c779e16770709f887128c6e5a1f86faf9c3aea..ba64d8fe17c1e3dd10e854ac39f7f2111296e662 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    341,
 /**/
     340,
 /**/