Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit OpenBSD term.c rev. 1.13 2009/12/11 18:58:59 jacekm
details: https://anonhg.NetBSD.org/src/rev/f4eabf194e85
branches: trunk
changeset: 343579:f4eabf194e85
user: christos <christos%NetBSD.org@localhost>
date: Mon Feb 15 15:35:03 2016 +0000
description:
OpenBSD term.c rev. 1.13 2009/12/11 18:58:59 jacekm
fix two memory leaks
diffstat:
lib/libedit/terminal.c | 39 ++++++++++++++++++++++++++++-----------
1 files changed, 28 insertions(+), 11 deletions(-)
diffs (111 lines):
diff -r 2345e690c36d -r f4eabf194e85 lib/libedit/terminal.c
--- a/lib/libedit/terminal.c Mon Feb 15 15:30:50 2016 +0000
+++ b/lib/libedit/terminal.c Mon Feb 15 15:35:03 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: terminal.c,v 1.16 2016/02/14 14:49:34 christos Exp $ */
+/* $NetBSD: terminal.c,v 1.17 2016/02/15 15:35:03 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.16 2016/02/14 14:49:34 christos Exp $");
+__RCSID("$NetBSD: terminal.c,v 1.17 2016/02/15 15:35:03 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -272,31 +272,45 @@
el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
sizeof(*el->el_terminal.t_buf));
if (el->el_terminal.t_buf == NULL)
- return -1;
+ goto fail1;
el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
sizeof(*el->el_terminal.t_cap));
if (el->el_terminal.t_cap == NULL)
- return -1;
+ goto fail2;
el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
sizeof(*el->el_terminal.t_fkey));
if (el->el_terminal.t_fkey == NULL)
- return -1;
+ goto fail3;
el->el_terminal.t_loc = 0;
el->el_terminal.t_str = el_malloc(T_str *
sizeof(*el->el_terminal.t_str));
if (el->el_terminal.t_str == NULL)
- return -1;
+ goto fail4;
(void) memset(el->el_terminal.t_str, 0, T_str *
sizeof(*el->el_terminal.t_str));
el->el_terminal.t_val = el_malloc(T_val *
sizeof(*el->el_terminal.t_val));
if (el->el_terminal.t_val == NULL)
- return -1;
+ goto fail5;
(void) memset(el->el_terminal.t_val, 0, T_val *
sizeof(*el->el_terminal.t_val));
(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:
+ return -1;
}
/* terminal_end():
@@ -418,14 +432,14 @@
b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return -1;
+ goto done;
for (i = 0; i < c->v; i++) {
b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
el_free(b[i]);
el_free(b);
- return -1;
+ goto done;
}
}
b[c->v] = NULL;
@@ -433,19 +447,22 @@
b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return -1;
+ goto done;
for (i = 0; i < c->v; i++) {
b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
el_free(b[i]);
el_free(b);
- return -1;
+ goto done;
}
}
b[c->v] = NULL;
el->el_vdisplay = b;
return 0;
+done:
+ terminal_free_display(el);
+ return -1;
}
Home |
Main Index |
Thread Index |
Old Index