diff options
| author | christos <christos@NetBSD.org> | 2022-10-30 19:11:31 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2022-10-30 19:11:31 +0000 |
| commit | 0a0d5a7574d217dd67342c93e8f61a43a6e96301 (patch) | |
| tree | 6cacca829db1512d1578c999afd6fb6e1a806277 /lib/libedit | |
| parent | c9cb6a172f424ed861b0a67f392acbbe805e82eb (diff) | |
improvements in malloc/free handling.
Diffstat (limited to 'lib/libedit')
| -rw-r--r-- | lib/libedit/chared.c | 11 | ||||
| -rw-r--r-- | lib/libedit/chartype.c | 6 | ||||
| -rw-r--r-- | lib/libedit/el.c | 6 | ||||
| -rw-r--r-- | lib/libedit/filecomplete.c | 6 | ||||
| -rw-r--r-- | lib/libedit/map.c | 13 | ||||
| -rw-r--r-- | lib/libedit/read.c | 25 | ||||
| -rw-r--r-- | lib/libedit/read.h | 4 | ||||
| -rw-r--r-- | lib/libedit/readline.c | 8 | ||||
| -rw-r--r-- | lib/libedit/terminal.c | 29 |
9 files changed, 56 insertions, 52 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c index ff5545bbe16..03d31ddeec8 100644 --- a/lib/libedit/chared.c +++ b/lib/libedit/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.62 2022/02/08 21:13:22 rillig Exp $ */ +/* $NetBSD: chared.c,v 1.63 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: chared.c,v 1.62 2022/02/08 21:13:22 rillig Exp $"); +__RCSID("$NetBSD: chared.c,v 1.63 2022/10/30 19:11:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -414,7 +414,7 @@ ch_init(EditLine *el) el->el_chared.c_redo.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_chared.c_redo.buf)); if (el->el_chared.c_redo.buf == NULL) - return -1; + goto out; el->el_chared.c_redo.pos = el->el_chared.c_redo.buf; el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ; el->el_chared.c_redo.cmd = ED_UNASSIGNED; @@ -425,7 +425,7 @@ ch_init(EditLine *el) el->el_chared.c_kill.buf = el_calloc(EL_BUFSIZ, sizeof(*el->el_chared.c_kill.buf)); if (el->el_chared.c_kill.buf == NULL) - return -1; + goto out; el->el_chared.c_kill.mark = el->el_line.buffer; el->el_chared.c_kill.last = el->el_chared.c_kill.buf; el->el_chared.c_resizefun = NULL; @@ -442,6 +442,9 @@ ch_init(EditLine *el) el->el_state.lastcmd = ED_UNASSIGNED; return 0; +out: + ch_end(el); + return -1; } /* ch_reset(): diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c index 3df4af69b51..9c74cfeb677 100644 --- a/lib/libedit/chartype.c +++ b/lib/libedit/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.36 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.35 2019/07/23 10:18:52 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.36 2022/10/30 19:11:31 christos Exp $"); #endif /* not lint && not SCCSID */ #include <ctype.h> @@ -158,6 +158,8 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) return NULL; wargv = el_calloc((size_t)(argc + 1), sizeof(*wargv)); + if (wargv == NULL) + return NULL; for (i = 0, p = conv->wbuff; i < argc; ++i) { if (!argv[i]) { /* don't pass null pointers to mbstowcs */ diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 47b76d7a530..2c06e32de9f 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.100 2021/08/15 10:08:41 christos Exp $ */ +/* $NetBSD: el.c,v 1.101 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; #else -__RCSID("$NetBSD: el.c,v 1.100 2021/08/15 10:08:41 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.101 2022/10/30 19:11:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -142,7 +142,7 @@ el_end(EditLine *el) if (!(el->el_flags & NO_TTY)) tty_end(el, TCSAFLUSH); ch_end(el); - read_end(el->el_read); + read_end(el); search_end(el); hist_end(el); prompt_end(el); diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c index f1ed03f72cf..1a3aded5971 100644 --- a/lib/libedit/filecomplete.c +++ b/lib/libedit/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.70 2022/03/12 15:29:17 christos Exp $ */ +/* $NetBSD: filecomplete.c,v 1.71 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.70 2022/03/12 15:29:17 christos Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.71 2022/10/30 19:11:31 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -637,6 +637,8 @@ find_word_to_complete(const wchar_t * cursor, const wchar_t * buffer, return unescaped_word; } temp = el_malloc((len + 1) * sizeof(*temp)); + if (temp == NULL) + return NULL; (void) wcsncpy(temp, ctemp, len); temp[len] = '\0'; return temp; diff --git a/lib/libedit/map.c b/lib/libedit/map.c index 321bb353922..57d3038ab2e 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.54 2021/08/29 09:41:59 christos Exp $ */ +/* $NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: map.c,v 1.54 2021/08/29 09:41:59 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.55 2022/10/30 19:11:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -918,18 +918,18 @@ map_init(EditLine *el) return -1; el->el_map.key = el_calloc(N_KEYS, sizeof(*el->el_map.key)); if (el->el_map.key == NULL) - return -1; + goto out; el->el_map.emacs = el_map_emacs; el->el_map.vic = el_map_vi_command; el->el_map.vii = el_map_vi_insert; el->el_map.help = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.help)); if (el->el_map.help == NULL) - return -1; + goto out; (void) memcpy(el->el_map.help, el_func_help, sizeof(*el->el_map.help) * EL_NUM_FCNS); el->el_map.func = el_calloc(EL_NUM_FCNS, sizeof(*el->el_map.func)); if (el->el_map.func == NULL) - return -1; + goto out; memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func) * EL_NUM_FCNS); el->el_map.nfunc = EL_NUM_FCNS; @@ -940,6 +940,9 @@ map_init(EditLine *el) map_init_emacs(el); #endif /* VIDEFAULT */ return 0; +out: + map_end(el); + return -1; } diff --git a/lib/libedit/read.c b/lib/libedit/read.c index a49a304de97..8026ca4a209 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.107 2021/08/15 10:08:41 christos Exp $ */ +/* $NetBSD: read.c,v 1.108 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.107 2021/08/15 10:08:41 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.108 2022/10/30 19:11:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -89,28 +89,31 @@ read_init(EditLine *el) return -1; ma = &el->el_read->macros; - if ((ma->macro = el_calloc(EL_MAXMACRO, sizeof(*ma->macro))) == NULL) { - free(el->el_read); - return -1; - } + if ((ma->macro = el_calloc(EL_MAXMACRO, sizeof(*ma->macro))) == NULL) + goto out; ma->level = -1; ma->offset = 0; /* builtin read_char */ el->el_read->read_char = read_char; return 0; +out: + read_end(el); + return -1; } /* el_read_end(): * Free the data structures used by the read stuff. */ libedit_private void -read_end(struct el_read_t *el_read) +read_end(EditLine *el) { - read_clearmacros(&el_read->macros); - el_free(el_read->macros.macro); - el_read->macros.macro = NULL; - el_free(el_read); + + read_clearmacros(&el->el_read->macros); + el_free(el->el_read->macros.macro); + el->el_read->macros.macro = NULL; + el_free(el->el_read); + el->el_read = NULL; } /* el_read_setfn(): diff --git a/lib/libedit/read.h b/lib/libedit/read.h index 1acf5d67637..8b710708f6f 100644 --- a/lib/libedit/read.h +++ b/lib/libedit/read.h @@ -1,4 +1,4 @@ -/* $NetBSD: read.h,v 1.12 2016/05/22 19:44:26 christos Exp $ */ +/* $NetBSD: read.h,v 1.13 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #define _h_el_read libedit_private int read_init(EditLine *); -libedit_private void read_end(struct el_read_t *); +libedit_private void read_end(EditLine *); libedit_private void read_prepare(EditLine *); libedit_private void read_finish(EditLine *); libedit_private int el_read_setfn(struct el_read_t *, el_rfunc_t); diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c index 84506db4939..d726c415c2c 100644 --- a/lib/libedit/readline.c +++ b/lib/libedit/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.176 2022/09/21 01:33:53 christos Exp $ */ +/* $NetBSD: readline.c,v 1.177 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.176 2022/09/21 01:33:53 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.177 2022/10/30 19:11:31 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/types.h> @@ -240,7 +240,7 @@ _default_history_file(void) return NULL; len = strlen(p->pw_dir) + sizeof("/.history"); - if ((path = malloc(len)) == NULL) + if ((path = el_malloc(len)) == NULL) return NULL; (void)snprintf(path, len, "%s/.history", p->pw_dir); @@ -2331,6 +2331,8 @@ rl_copy_text(int from, int to) len = (size_t)(to - from); out = el_malloc((size_t)len + 1); + if (out == NULL) + return NULL; (void)strlcpy(out, li->buffer + from , len); return out; diff --git a/lib/libedit/terminal.c b/lib/libedit/terminal.c index 3bea1fc27a8..6e5a5a04f01 100644 --- a/lib/libedit/terminal.c +++ b/lib/libedit/terminal.c @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.c,v 1.44 2021/09/09 20:24:07 christos Exp $ */ +/* $NetBSD: terminal.c,v 1.45 2022/10/30 19:11:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: terminal.c,v 1.44 2021/09/09 20:24:07 christos Exp $"); +__RCSID("$NetBSD: terminal.c,v 1.45 2022/10/30 19:11:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -272,40 +272,29 @@ terminal_init(EditLine *el) el->el_terminal.t_buf = el_calloc(TC_BUFSIZE, sizeof(*el->el_terminal.t_buf)); if (el->el_terminal.t_buf == NULL) - goto fail1; + return -1; el->el_terminal.t_cap = el_calloc(TC_BUFSIZE, sizeof(*el->el_terminal.t_cap)); if (el->el_terminal.t_cap == NULL) - goto fail2; + goto out; el->el_terminal.t_fkey = el_calloc(A_K_NKEYS, sizeof(*el->el_terminal.t_fkey)); if (el->el_terminal.t_fkey == NULL) - goto fail3; + goto out; el->el_terminal.t_loc = 0; el->el_terminal.t_str = el_calloc(T_str, sizeof(*el->el_terminal.t_str)); if (el->el_terminal.t_str == NULL) - goto fail4; + goto out; el->el_terminal.t_val = el_calloc(T_val, sizeof(*el->el_terminal.t_val)); if (el->el_terminal.t_val == NULL) - goto fail5; + goto out; (void) terminal_set(el, NULL); terminal_init_arrow(el); return 0; -fail5: - free(el->el_terminal.t_str); - el->el_terminal.t_str = NULL; -fail4: - free(el->el_terminal.t_fkey); - el->el_terminal.t_fkey = NULL; -fail3: - free(el->el_terminal.t_cap); - el->el_terminal.t_cap = NULL; -fail2: - free(el->el_terminal.t_buf); - el->el_terminal.t_buf = NULL; -fail1: +out: + terminal_end(el); return -1; } |
