To: vim-dev@vim.org Subject: Patch 6.0.140 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.140 Problem: Memory allocated for local mappings and abbreviations is leaked when the buffer is wiped out. Solution: Clear the local mappings when deleting a buffer. Files: src/buffer.c, src/getchar.c, src/proto/getchar.pro, src/vim.h *** ../vim60.139/src/buffer.c Mon Jan 14 12:49:05 2002 --- src/buffer.c Wed Jan 16 13:05:47 2002 *************** *** 507,512 **** --- 507,516 ---- #endif #ifdef FEAT_USR_CMDS uc_clear(&buf->b_ucmds); /* clear local user commands */ + #ifdef FEAT_LOCALMAP + map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ + map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ + #endif #endif free_buf_options(buf, TRUE); #ifdef FEAT_MBYTE *** ../vim60.139/src/getchar.c Tue Jan 15 14:28:35 2002 --- src/getchar.c Wed Jan 16 12:49:18 2002 *************** *** 3278,3287 **** int forceit; int abbr; { - mapblock_T *mp, **mpp; int mode; - int hash; - int new_hash; #ifdef FEAT_LOCALMAP int local; --- 3278,3284 ---- *************** *** 3293,3301 **** } #endif - validate_maphash(); - mode = get_map_mode(&cmdp, forceit); for (hash = 0; hash < 256; ++hash) { --- 3290,3320 ---- } #endif mode = get_map_mode(&cmdp, forceit); + map_clear_int(curbuf, mode, + #ifdef FEAT_LOCALMAP + local, + #else + FALSE, + #endif + abbr); + } + + /* + * Clear all mappings in "mode". + */ + void + map_clear_int(buf, mode, local, abbr) + buf_T *buf; /* buffer for local mappings */ + int mode; /* mode in which to delete */ + int local; /* TRUE for buffer-local mappings */ + int abbr; /* TRUE for abbreviations */ + { + mapblock_T *mp, **mpp; + int hash; + int new_hash; + + validate_maphash(); for (hash = 0; hash < 256; ++hash) { *************** *** 3305,3311 **** break; #ifdef FEAT_LOCALMAP if (local) ! mpp = &curbuf->b_first_abbr; else #endif mpp = &first_abbr; --- 3324,3330 ---- break; #ifdef FEAT_LOCALMAP if (local) ! mpp = &buf->b_first_abbr; else #endif mpp = &first_abbr; *************** *** 3314,3320 **** { #ifdef FEAT_LOCALMAP if (local) ! mpp = &curbuf->b_maphash[hash]; else #endif mpp = &maphash[hash]; --- 3333,3339 ---- { #ifdef FEAT_LOCALMAP if (local) ! mpp = &buf->b_maphash[hash]; else #endif mpp = &maphash[hash]; *************** *** 3340,3347 **** #ifdef FEAT_LOCALMAP if (local) { ! mp->m_next = curbuf->b_maphash[new_hash]; ! curbuf->b_maphash[new_hash] = mp; } else #endif --- 3359,3366 ---- #ifdef FEAT_LOCALMAP if (local) { ! mp->m_next = buf->b_maphash[new_hash]; ! buf->b_maphash[new_hash] = mp; } else #endif *** ../vim60.139/src/proto/getchar.pro Sun Oct 28 21:23:45 2001 --- src/proto/getchar.pro Wed Jan 16 13:05:25 2002 *************** *** 41,46 **** --- 41,47 ---- int do_map __ARGS((int maptype, char_u *arg, int mode, int abbrev)); int get_map_mode __ARGS((char_u **cmdp, int forceit)); void map_clear __ARGS((char_u *cmdp, char_u *arg, int forceit, int abbr)); + void map_clear_int __ARGS((buf_T *buf, int mode, int local, int abbr)); int map_to_exists __ARGS((char_u *str, char_u *modechars)); int map_to_exists_mode __ARGS((char_u *rhs, int mode)); char_u *set_context_in_map_cmd __ARGS((expand_T *xp, char_u *cmd, char_u *arg, int forceit, int isabbrev, int isunmap, cmdidx_T cmdidx)); *** ../vim60.139/src/vim.h Wed Sep 19 16:57:09 2001 --- src/vim.h Wed Jan 16 13:03:57 2002 *************** *** 501,506 **** --- 501,507 ---- #define INSERT 0x10 /* Insert mode */ #define LANGMAP 0x20 /* Language mapping, can be combined with INSERT and CMDLINE */ + #define MAP_ALL_MODES 0x3f /* all mode bits used for mapping */ #define REPLACE_FLAG 0x40 /* Replace mode flag */ #define REPLACE (REPLACE_FLAG + INSERT) *** ../vim60.139/src/version.c Wed Jan 16 12:28:44 2002 --- src/version.c Wed Jan 16 13:45:27 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 140, /**/ -- hundred-and-one symptoms of being an internet addict: 6. You refuse to go to a vacation spot with no electricity and no phone lines. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///