diff --git a/src/evalfunc.c b/src/evalfunc.c index 3aeda7e11b19f8..24b2ff4135411b 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -5840,7 +5840,10 @@ f_getchangelist(typval_T *argvars, typval_T *rettv) if ((d = dict_alloc()) == NULL) return; if (list_append_dict(l, d) == FAIL) + { + dict_unref(d); return; + } dict_add_number(d, "lnum", (long)buf->b_changelist[i].lnum); dict_add_number(d, "col", (long)buf->b_changelist[i].col); dict_add_number(d, "coladd", (long)buf->b_changelist[i].coladd); @@ -6058,7 +6061,10 @@ f_getjumplist(typval_T *argvars, typval_T *rettv) if ((d = dict_alloc()) == NULL) return; if (list_append_dict(l, d) == FAIL) + { + dict_unref(d); return; + } dict_add_number(d, "lnum", (long)wp->w_jumplist[i].fmark.mark.lnum); dict_add_number(d, "col", (long)wp->w_jumplist[i].fmark.mark.col); dict_add_number(d, "coladd", (long)wp->w_jumplist[i].fmark.mark.coladd); @@ -9498,7 +9504,10 @@ get_matches_in_str( if (d == NULL) return FAIL; if (list_append_dict(mlist, d) == FAIL) + { + dict_unref(d); return FAIL; + } if (dict_add_number(d, matchbuf ? "lnum" : "idx", idx) == FAIL) return FAIL; diff --git a/src/evalvars.c b/src/evalvars.c index 9b98ae731011aa..b1c0e454a959b9 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -1363,7 +1363,10 @@ ex_let_vars( copy_tv(TUPLE_ITEM(tuple, idx), &new_tv); if (tuple_append_tv(new_tuple, &new_tv) == FAIL) + { + tuple_unref(new_tuple); return FAIL; + } idx++; } diff --git a/src/highlight.c b/src/highlight.c index 717a8f5fb66cdf..94f8c3fac7d7b6 100644 --- a/src/highlight.c +++ b/src/highlight.c @@ -5559,7 +5559,7 @@ highlight_get_info(int hl_idx, int resolve_link) { dict_T *dict; hl_group_T *sgp; - dict_T *attr_dict; + dict_T *attr_dict = NULL; int hlgid; dict = dict_alloc(); @@ -5589,8 +5589,11 @@ highlight_get_info(int hl_idx, int resolve_link) { attr_dict = highlight_get_attr_dict(sgp->sg_term); if (attr_dict != NULL) + { if (dict_add_dict(dict, "term", attr_dict) == FAIL) goto error; + attr_dict = NULL; + } } if (sgp->sg_start != NULL) if (dict_add_string(dict, "start", sgp->sg_start) == FAIL) @@ -5602,8 +5605,11 @@ highlight_get_info(int hl_idx, int resolve_link) { attr_dict = highlight_get_attr_dict(sgp->sg_cterm); if (attr_dict != NULL) + { if (dict_add_dict(dict, "cterm", attr_dict) == FAIL) goto error; + attr_dict = NULL; + } } if (sgp->sg_cterm_fg != 0) if (dict_add_string(dict, "ctermfg", @@ -5625,8 +5631,11 @@ highlight_get_info(int hl_idx, int resolve_link) { attr_dict = highlight_get_attr_dict(sgp->sg_gui); if (attr_dict != NULL) + { if (dict_add_dict(dict, "gui", attr_dict) == FAIL) goto error; + attr_dict = NULL; + } } if (sgp->sg_gui_fg_name != NULL) if (dict_add_string(dict, "guifg", @@ -5663,7 +5672,8 @@ highlight_get_info(int hl_idx, int resolve_link) return dict; error: - vim_free(dict); + dict_unref(attr_dict); + dict_unref(dict); return NULL; } diff --git a/src/sign.c b/src/sign.c index a8dfd05eeecf3b..1d735de001460e 100644 --- a/src/sign.c +++ b/src/sign.c @@ -1838,7 +1838,10 @@ sign_getlist(char_u *name, list_T *retlist) return; if (list_append_dict(retlist, dict) == FAIL) + { + dict_unref(dict); return; + } sign_getinfo(sp, dict); diff --git a/src/userfunc.c b/src/userfunc.c index 66b55449e3db2b..eb1f7103580e4d 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -6684,14 +6684,20 @@ add_defer(char_u *name, int argcount_arg, typval_T *argvars) if (in_def_function()) { if (add_defer_function(saved_name, argcount, argvars) == OK) + { argcount = 0; + ret = OK; + } } else { if (current_funccal->fc_defer.ga_itemsize == 0) ga_init2(¤t_funccal->fc_defer, sizeof(defer_T), 10); if (ga_grow(¤t_funccal->fc_defer, 1) == FAIL) + { + vim_free(saved_name); goto theend; + } dr = ((defer_T *)current_funccal->fc_defer.ga_data) + current_funccal->fc_defer.ga_len++; dr->dr_name = saved_name; @@ -6701,8 +6707,8 @@ add_defer(char_u *name, int argcount_arg, typval_T *argvars) --argcount; dr->dr_argvars[argcount] = argvars[argcount]; } + ret = OK; } - ret = OK; theend: while (--argcount >= 0) diff --git a/src/vim9cmds.c b/src/vim9cmds.c index 1a8ff15f48a3ee..2d9835389960e3 100644 --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -2433,13 +2433,17 @@ compile_exec(char_u *line_arg, exarg_T *eap, cctx_T *cctx) } p += 2; if (compile_expr0(&p, cctx) == FAIL) + { + vim_free(tofree); return NULL; + } may_generate_2STRING(-1, TOSTRING_TOLERANT, cctx); ++count; p = skipwhite(p); if (*p != '`') { emsg(_(e_missing_backtick)); + vim_free(tofree); return NULL; } start = p + 1; diff --git a/src/vim9expr.c b/src/vim9expr.c index a041a3e70a65a2..4331d3f5b0d5a0 100644 --- a/src/vim9expr.c +++ b/src/vim9expr.c @@ -1930,7 +1930,7 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) // {[expr]: value} uses an evaluated key. *arg = skipwhite(*arg + 1); if (compile_expr0(arg, cctx) == FAIL) - return FAIL; + goto failret; isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; if (isn->isn_type == ISN_PUSHNR) { @@ -1944,12 +1944,12 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) if (isn->isn_type == ISN_PUSHS) key = isn->isn_arg.string; else if (may_generate_2STRING(-1, TOSTRING_NONE, cctx) == FAIL) - return FAIL; + goto failret; *arg = skipwhite(*arg); if (**arg != ']') { emsg(_(e_missing_matching_bracket_after_dict_key)); - return FAIL; + goto failret; } ++*arg; } @@ -1960,9 +1960,9 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) // {name: value} use "name" as a literal key key = get_literal_key(arg); if (key == NULL) - return FAIL; + goto failret; if (generate_PUSHS(cctx, &key) == FAIL) - return FAIL; + goto failret; } // Check for duplicate keys, if using string keys. @@ -1990,13 +1990,13 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) semsg(_(e_no_white_space_allowed_before_str_str), ":", *arg); else semsg(_(e_missing_colon_in_dictionary_str), *arg); - return FAIL; + goto failret; } whitep = *arg + 1; if (!IS_WHITE_OR_NUL(*whitep)) { semsg(_(e_white_space_required_after_str_str), ":", *arg); - return FAIL; + goto failret; } if (may_get_next_line(whitep, arg, cctx) == FAIL) @@ -2006,7 +2006,7 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) } if (compile_expr0_ext(arg, cctx, &is_const) == FAIL) - return FAIL; + goto failret; if (!is_const) is_all_const = FALSE; ++count; @@ -2027,13 +2027,13 @@ compile_dict(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) if (IS_WHITE_OR_NUL(*whitep)) { semsg(_(e_no_white_space_allowed_before_str_str), ",", whitep); - return FAIL; + goto failret; } whitep = *arg + 1; if (!IS_WHITE_OR_NUL(*whitep)) { semsg(_(e_white_space_required_after_str_str), ",", *arg); - return FAIL; + goto failret; } *arg = skipwhite(whitep); } diff --git a/src/vim9type.c b/src/vim9type.c index 1bd94a60cb4b41..dfa6686a980114 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -147,6 +147,8 @@ alloc_type(type_T *type) return type; ret = ALLOC_ONE(type_T); + if (ret == NULL) + return NULL; *ret = *type; if (ret->tt_member != NULL) @@ -2720,13 +2722,16 @@ type_name_func(type_T *type, char **tofree) STRCPY((char *)ga.ga_data + ga.ga_len, ")"); else { - char *ret_free; + char *ret_free = NULL; char *ret_name = type_name(type->tt_member, &ret_free); int len; len = (int)STRLEN(ret_name) + 4; if (ga_grow(&ga, len) == FAIL) + { + vim_free(ret_free); goto failed; + } STRCPY((char *)ga.ga_data + ga.ga_len, "): "); STRCPY((char *)ga.ga_data + ga.ga_len + 3, ret_name); vim_free(ret_free);