aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-11-03 02:25:47 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-11-03 02:36:35 +0100
commit059cb81817cfa9d56ac4168f738836adf6dd6caa (patch)
tree8fea0975593ee01a742f823bb138ec5f19559470
parentc1251f397885361cd583d06f2514ad635fabf7b8 (diff)
downloadtermo-059cb81817cfa9d56ac4168f738836adf6dd6caa.tar.gz
termo-059cb81817cfa9d56ac4168f738836adf6dd6caa.tar.xz
termo-059cb81817cfa9d56ac4168f738836adf6dd6caa.zip
Try to fix terminfo loading
It could lead to crashing the PTY under OpenBSD and ncurses. Fixed some unibiliums leaks while at it.
-rw-r--r--driver-ti.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/driver-ti.c b/driver-ti.c
index 719dc2e..46a1d8b 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -177,6 +177,7 @@ static bool
load_terminfo (termo_ti_t *ti, const char *term)
{
const char *mouse_report_string = NULL;
+ bool result = false;
#ifdef HAVE_UNIBILIUM
unibi_term *unibi = unibi_from_term (term);
@@ -191,8 +192,12 @@ load_terminfo (termo_ti_t *ti, const char *term)
// Have to cast away the const. But it's OK - we know terminfo won't
// really modify term
int err;
+ TERMINAL *saved_term = set_curterm (NULL);
if (setupterm ((char *) term, 1, &err) != OK)
+ {
+ set_curterm (saved_term);
return false;
+ }
for (int i = 0; strfnames[i]; i++)
{
@@ -227,8 +232,7 @@ load_terminfo (termo_ti_t *ti, const char *term)
if (node && !insert_seq (ti, value, node))
{
free (node);
- // FIXME: unibi leak
- return false;
+ goto fail;
}
}
@@ -255,14 +259,13 @@ load_terminfo (termo_ti_t *ti, const char *term)
trie_node_t *node = malloc (sizeof *node);
if (!node)
- return false;
+ goto fail;
node->type = TYPE_MOUSE;
if (!insert_seq (ti, mouse_report_string, node))
{
free (node);
- // FIXME: unibi leak
- return false;
+ goto fail;
}
}
@@ -305,11 +308,14 @@ load_terminfo (termo_ti_t *ti, const char *term)
else
ti->stop_string = NULL;
+ result = true;
+fail:
#ifdef HAVE_UNIBILIUM
unibi_destroy (unibi);
+#else
+ del_curterm (set_curterm (saved_term));
#endif
-
- return true;
+ return result;
}
static bool