Mercurial > vim
comparison src/buffer.c @ 10952:835604f3c37a v8.0.0365
patch 8.0.0365: might free a dict item that wasn't allocated
commit https://github.com/vim/vim/commit/95c526e1f6d76acafee4b21f5701d6d6ac8c4b5f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 25 14:59:34 2017 +0100
patch 8.0.0365: might free a dict item that wasn't allocated
Problem: Might free a dict item that wasn't allocated.
Solution: Call dictitem_free(). (Nikolai Pavlov) Use this for
b:changedtick.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 25 Feb 2017 15:00:05 +0100 |
parents | fd1760f8c215 |
children | 8ff62b4cffae |
comparison
equal
deleted
inserted
replaced
10951:32704a1de17c | 10952:835604f3c37a |
---|---|
830 { | 830 { |
831 ++buf_free_count; | 831 ++buf_free_count; |
832 free_buffer_stuff(buf, TRUE); | 832 free_buffer_stuff(buf, TRUE); |
833 #ifdef FEAT_EVAL | 833 #ifdef FEAT_EVAL |
834 unref_var_dict(buf->b_vars); | 834 unref_var_dict(buf->b_vars); |
835 buf->b_changedtick = &buf->b_ct_val; | |
836 #endif | 835 #endif |
837 #ifdef FEAT_LUA | 836 #ifdef FEAT_LUA |
838 lua_buffer_free(buf); | 837 lua_buffer_free(buf); |
839 #endif | 838 #endif |
840 #ifdef FEAT_MZSCHEME | 839 #ifdef FEAT_MZSCHEME |
872 #endif | 871 #endif |
873 vim_free(buf); | 872 vim_free(buf); |
874 } | 873 } |
875 | 874 |
876 /* | 875 /* |
877 * Initializes buf->b_changedtick. | 876 * Initializes b:changedtick. |
878 */ | 877 */ |
879 static void | 878 static void |
880 init_changedtick(buf_T *buf) | 879 init_changedtick(buf_T *buf) |
881 { | 880 { |
882 #ifdef FEAT_EVAL | 881 dictitem_T *di = (dictitem_T *)&buf->b_ct_di; |
883 dictitem_T *di = dictitem_alloc((char_u *)"changedtick"); | 882 |
884 | 883 di->di_flags = DI_FLAGS_FIX | DI_FLAGS_RO; |
885 if (di != NULL) | 884 di->di_tv.v_type = VAR_NUMBER; |
886 { | 885 di->di_tv.v_lock = VAR_FIXED; |
887 di->di_flags |= DI_FLAGS_FIX | DI_FLAGS_RO; | 886 di->di_tv.vval.v_number = 0; |
888 di->di_tv.v_type = VAR_NUMBER; | 887 |
889 di->di_tv.v_lock = VAR_FIXED; | 888 STRCPY(buf->b_ct_di.di_key, "changedtick"); |
890 di->di_tv.vval.v_number = 0; | 889 (void)dict_add(buf->b_vars, di); |
891 if (dict_add(buf->b_vars, di) == OK) | |
892 buf->b_changedtick = &di->di_tv.vval.v_number; | |
893 else | |
894 { | |
895 vim_free(di); | |
896 buf->b_changedtick = &buf->b_ct_val; | |
897 } | |
898 } | |
899 else | |
900 #endif | |
901 buf->b_changedtick = &buf->b_ct_val; | |
902 } | 890 } |
903 | 891 |
904 /* | 892 /* |
905 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. | 893 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. |
906 */ | 894 */ |
917 ga_clear(&buf->b_s.b_langp); | 905 ga_clear(&buf->b_s.b_langp); |
918 #endif | 906 #endif |
919 } | 907 } |
920 #ifdef FEAT_EVAL | 908 #ifdef FEAT_EVAL |
921 { | 909 { |
922 varnumber_T tick = *buf->b_changedtick; | 910 varnumber_T tick = CHANGEDTICK(buf); |
923 | 911 |
924 vars_clear(&buf->b_vars->dv_hashtab); /* free all buffer variables */ | 912 vars_clear(&buf->b_vars->dv_hashtab); /* free all buffer variables */ |
925 hash_init(&buf->b_vars->dv_hashtab); | 913 hash_init(&buf->b_vars->dv_hashtab); |
926 init_changedtick(buf); | 914 init_changedtick(buf); |
927 *buf->b_changedtick = tick; | 915 CHANGEDTICK(buf) = tick; |
928 } | 916 } |
929 #endif | 917 #endif |
930 #ifdef FEAT_USR_CMDS | 918 #ifdef FEAT_USR_CMDS |
931 uc_clear(&buf->b_ucmds); /* clear local user commands */ | 919 uc_clear(&buf->b_ucmds); /* clear local user commands */ |
932 #endif | 920 #endif |