To: vim_dev@googlegroups.com Subject: Patch 8.1.0660 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0660 Problem: sign_unplace() may leak memory. Solution: Free the group name before returning. Add a few more tests. (Yegappan Lakshmanan) Files: src/evalfunc.c, src/testdir/test_signs.vim *** ../vim-8.1.0659/src/evalfunc.c 2018-12-29 18:53:07.843607433 +0100 --- src/evalfunc.c 2018-12-29 20:42:30.370357956 +0100 *************** *** 11578,11584 **** if (argvars[1].v_type != VAR_DICT) { EMSG(_(e_dictreq)); ! return; } dict = argvars[1].vval.v_dict; --- 11578,11584 ---- if (argvars[1].v_type != VAR_DICT) { EMSG(_(e_dictreq)); ! goto cleanup; } dict = argvars[1].vval.v_dict; *************** *** 11589,11595 **** { EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(&di->di_tv)); ! return; } } if (dict_find(dict, (char_u *)"id", -1) != NULL) --- 11589,11595 ---- { EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(&di->di_tv)); ! goto cleanup; } } if (dict_find(dict, (char_u *)"id", -1) != NULL) *************** *** 11608,11613 **** --- 11608,11615 ---- if (sign_unplace(sign_id, group, buf, 0) == OK) rettv->vval.v_number = 0; } + + cleanup: vim_free(group); } #endif *** ../vim-8.1.0659/src/testdir/test_signs.vim 2018-12-29 18:53:07.843607433 +0100 --- src/testdir/test_signs.vim 2018-12-29 20:48:20.911472019 +0100 *************** *** 385,390 **** --- 385,392 ---- \ {"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,428 **** \ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:') call assert_fails("call sign_unplace('', \ {'id' : 20, 'buffer' : ''})", 'E158:') ! call assert_fails("call sign_unplace('', \ {'id' : 20, 'buffer' : 200})", 'E158:') ! call assert_fails("call sign_unplace('', 'mySign')", 'E715:') " Tests for sign_undefine() call assert_equal(0, sign_undefine("sign1")) --- 422,430 ---- \ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:') call assert_fails("call sign_unplace('', \ {'id' : 20, 'buffer' : ''})", 'E158:') ! call assert_fails("call sign_unplace('g1', \ {'id' : 20, 'buffer' : 200})", 'E158:') ! call assert_fails("call sign_unplace('g1', 'mySign')", 'E715:') " Tests for sign_undefine() call assert_equal(0, sign_undefine("sign1")) *************** *** 664,670 **** call delete("Xsign") call sign_unplace('*') call sign_undefine() ! enew | only endfunc " Place signs used for ":sign unplace" command test --- 666,672 ---- call delete("Xsign") call sign_unplace('*') call sign_undefine() ! enew | only endfunc " Place signs used for ":sign unplace" command test *************** *** 1013,1019 **** call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign1") call delete("Xsign2") endfunc --- 1015,1021 ---- call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign1") call delete("Xsign2") endfunc *************** *** 1042,1047 **** --- 1044,1052 ---- 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,1055 **** call delete("Xsign") call sign_unplace('*') call sign_undefine() ! enew | only endfunc " Test for sign priority --- 1054,1060 ---- call delete("Xsign") call sign_unplace('*') call sign_undefine() ! enew | only endfunc " Test for sign priority *************** *** 1085,1090 **** --- 1090,1097 ---- " 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,1110 **** call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign") endfunc --- 1111,1117 ---- call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign") endfunc *************** *** 1146,1151 **** call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign") endfunc --- 1153,1158 ---- call sign_unplace('*') call sign_undefine() ! enew | only call delete("Xsign") endfunc *** ../vim-8.1.0659/src/version.c 2018-12-29 20:04:36.257512068 +0100 --- src/version.c 2018-12-29 20:57:28.734930503 +0100 *************** *** 801,802 **** --- 801,804 ---- { /* Add new patch number below this line */ + /**/ + 660, /**/ -- hundred-and-one symptoms of being an internet addict: 81. At social functions you introduce your husband as "my domain server." /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///