Vim is leaking memory when doing 'set keymap=' You can reproduce the memory leak by running the following script and observe memory usage (with 'top') which keeps increasing continuously:
:while 1 : set keymap=esperanto : set keymap= :endwhile The leak happens regardless of the keymap, I only chose 'esperanto' as an example. The same leak also happens when doing 'set arabic' & 'set noarabic' since it implies a 'set keymap=arabic'. Valgrind memory checker points to following location for the leak: ==7572== 4,856,970 bytes in 571,416 blocks are definitely lost in loss record 42 of 42 ==7572== at 0x4022AB8: malloc (vg_replace_malloc.c:207) ==7572== by 0x810FA74: lalloc (misc2.c:862) ==7572== by 0x810F990: alloc (misc2.c:761) ==7572== by 0x810FE2B: vim_strnsave (misc2.c:1179) ==7572== by 0x8062AA5: ex_loadkeymap (digraph.c:2493) ==7572== by 0x80A42F1: do_one_cmd (ex_docmd.c:2625) ==7572== by 0x80A1B98: do_cmdline (ex_docmd.c:1099) ==7572== by 0x809FE48: do_source (ex_cmds2.c:3119) ==7572== by 0x809F35F: source_callback (ex_cmds2.c:2563) ==7572== by 0x809F53C: do_in_runtimepath (ex_cmds2.c:2657) ==7572== by 0x809F389: source_runtime (ex_cmds2.c:2577) ==7572== by 0x806289F: keymap_init (digraph.c:2429) ==7572== by 0x813B623: did_set_string_option (option.c:5782) ==7572== by 0x81397C0: do_set (option.c:4659) ==7572== by 0x80B0F19: ex_set (ex_docmd.c:10862) ==7572== by 0x80A42F1: do_one_cmd (ex_docmd.c:2625) ==7572== by 0x80A1B98: do_cmdline (ex_docmd.c:1099) ==7572== by 0x809FE48: do_source (ex_cmds2.c:3119) ==7572== by 0x809F763: cmd_source (ex_cmds2.c:2746) ==7572== by 0x809F6B7: ex_source (ex_cmds2.c:2719) ==7572== by 0x80A42F1: do_one_cmd (ex_docmd.c:2625) ==7572== by 0x80A1B98: do_cmdline (ex_docmd.c:1099) ==7572== by 0x80A1238: do_cmdline_cmd (ex_docmd.c:705) ==7572== by 0x80E5357: exe_commands (main.c:2665) ==7572== by 0x80E2D87: main (main.c:875) Attached patch fixes it. I'm using Vim 7.1.330 (huge) on Linux x86. Regards -- Dominique --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
Index: digraph.c =================================================================== RCS file: /cvsroot/vim/vim7/src/digraph.c,v retrieving revision 1.12 diff -c -r1.12 digraph.c *** digraph.c 3 Jan 2008 16:54:33 -0000 1.12 --- digraph.c 23 Jun 2008 20:07:22 -0000 *************** *** 2538,2556 **** char_u buf[KMAP_MAXLEN + 10]; int i; char_u *save_cpo = p_cpo; if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) return; /* Set 'cpoptions' to "C" to avoid line continuation. */ p_cpo = (char_u *)"C"; /* clear the ":lmap"s */ for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { ! vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", ! ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from); (void)do_map(1, buf, LANGMAP, FALSE); } p_cpo = save_cpo; --- 2538,2560 ---- char_u buf[KMAP_MAXLEN + 10]; int i; char_u *save_cpo = p_cpo; + kmap_T *kp; if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) return; + kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; + /* Set 'cpoptions' to "C" to avoid line continuation. */ p_cpo = (char_u *)"C"; /* clear the ":lmap"s */ for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { ! vim_snprintf((char *)buf, sizeof(buf), "<buffer> %s", kp[i].from); (void)do_map(1, buf, LANGMAP, FALSE); + vim_free(kp[i].from); + vim_free(kp[i].to); } p_cpo = save_cpo;