]> granicus.if.org Git - vim/commitdiff
patch 8.1.0660: sign_cleanup() may leak memory v8.1.0660
authorBram Moolenaar <Bram@vim.org>
Sat, 29 Dec 2018 20:00:27 +0000 (21:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 29 Dec 2018 20:00:27 +0000 (21:00 +0100)
Problem:    sign_cleanup() may leak memory.
Solution:   Free the group name before returning.  Add a few more tests.
            (Yegappan Lakshmanan)

src/evalfunc.c
src/testdir/test_signs.vim
src/version.c

index 13e6d6e2696460e25f7a1e07ef1db4ab82aeeef2..2e9b16a3e3edd38171e68ad395182cce9f4d9aac 100644 (file)
@@ -11578,7 +11578,7 @@ f_sign_unplace(typval_T *argvars, typval_T *rettv)
        if (argvars[1].v_type != VAR_DICT)
        {
            EMSG(_(e_dictreq));
-           return;
+           goto cleanup;
        }
        dict = argvars[1].vval.v_dict;
 
@@ -11589,7 +11589,7 @@ f_sign_unplace(typval_T *argvars, typval_T *rettv)
            {
                EMSG2(_("E158: Invalid buffer name: %s"),
                                                tv_get_string(&di->di_tv));
-               return;
+               goto cleanup;
            }
        }
        if (dict_find(dict, (char_u *)"id", -1) != NULL)
@@ -11608,6 +11608,8 @@ f_sign_unplace(typval_T *argvars, typval_T *rettv)
        if (sign_unplace(sign_id, group, buf, 0) == OK)
            rettv->vval.v_number = 0;
     }
+
+cleanup:
     vim_free(group);
 }
 #endif
index 5917fc6831f66a07303af3c1eae3c4348166954f..b26312a6b65043455e2402b021bb036888730efc 100644 (file)
@@ -385,6 +385,8 @@ func Test_sign_funcs()
              \ {"lnum" : -1})', 'E885:')
   call assert_fails('call sign_place(22, "", "sign1", "Xsign",
              \ {"lnum" : 0})', 'E885:')
+  call assert_fails('call sign_place(22, "", "sign1", "Xsign",
+             \ {"lnum" : []})', 'E745:')
   call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10}))
 
   " Tests for sign_getplaced()
@@ -420,9 +422,9 @@ func Test_sign_funcs()
              \ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:')
   call assert_fails("call sign_unplace('',
              \ {'id' : 20, 'buffer' : ''})", 'E158:')
-  call assert_fails("call sign_unplace('',
+  call assert_fails("call sign_unplace('g1',
              \ {'id' : 20, 'buffer' : 200})", 'E158:')
-  call assert_fails("call sign_unplace('', 'mySign')", 'E715:')
+  call assert_fails("call sign_unplace('g1', 'mySign')", 'E715:')
 
   " Tests for sign_undefine()
   call assert_equal(0, sign_undefine("sign1"))
@@ -664,7 +666,7 @@ func Test_sign_group()
   call delete("Xsign")
   call sign_unplace('*')
   call sign_undefine()
-  enew  | only
+  enew | only
 endfunc
 
 " Place signs used for ":sign unplace" command test
@@ -1013,7 +1015,7 @@ func Test_sign_unplace()
 
   call sign_unplace('*')
   call sign_undefine()
-  enew  | only
+  enew | only
   call delete("Xsign1")
   call delete("Xsign2")
 endfunc
@@ -1042,6 +1044,9 @@ func Test_sign_id_autogen()
 
   call assert_equal(1, sign_place(0, 'g1', 'sign1', 'Xsign',
              \ {'lnum' : 11}))
+  " Check for the next generated sign id in this group
+  call assert_equal(2, sign_place(0, 'g1', 'sign1', 'Xsign',
+             \ {'lnum' : 12}))
   call assert_equal(0, sign_unplace('g1', {'id' : 1}))
   call assert_equal(10,
              \ sign_getplaced('Xsign', {'id' : 1})[0].signs[0].lnum)
@@ -1049,7 +1054,7 @@ func Test_sign_id_autogen()
   call delete("Xsign")
   call sign_unplace('*')
   call sign_undefine()
-  enew  | only
+  enew | only
 endfunc
 
 " Test for sign priority
@@ -1085,6 +1090,8 @@ func Test_sign_priority()
   " Error case
   call assert_fails("call sign_place(1, 'g1', 'sign1', 'Xsign',
              \ [])", 'E715:')
+  call assert_fails("call sign_place(1, 'g1', 'sign1', 'Xsign',
+             \ {'priority' : []})", 'E745:')
   call sign_unplace('*')
 
   " Tests for the :sign place command with priority
@@ -1104,7 +1111,7 @@ func Test_sign_priority()
 
   call sign_unplace('*')
   call sign_undefine()
-  enew  | only
+  enew | only
   call delete("Xsign")
 endfunc
 
@@ -1146,6 +1153,6 @@ func Test_sign_memfailures()
 
   call sign_unplace('*')
   call sign_undefine()
-  enew  | only
+  enew | only
   call delete("Xsign")
 endfunc
index e76bf4bd8c71d0f0d50857c25f3f2bf2aa942d86..c98fc5077b68be4421fcafc9dc3c6964458e5fc3 100644 (file)
@@ -799,6 +799,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    660,
 /**/
     659,
 /**/