aboutsummaryrefslogtreecommitdiff
path: root/termo.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-12-30 08:30:59 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-12-30 08:30:59 +0100
commit5b05b96ec0cbef6ed10adb1423cdedde09ee868e (patch)
tree69e15ab41f5367d07c2d1cff8d06d1022c7c0d7a /termo.c
parenta9b41e41b7789924465a7e5596a463ed93d8fc26 (diff)
downloadtermo-5b05b96ec0cbef6ed10adb1423cdedde09ee868e.tar.gz
termo-5b05b96ec0cbef6ed10adb1423cdedde09ee868e.tar.xz
termo-5b05b96ec0cbef6ed10adb1423cdedde09ee868e.zip
Backport TERMKEY_FLAG_NOSTART and fix two leaks
...that are notably still present in the original library.
Diffstat (limited to 'termo.c')
-rw-r--r--termo.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/termo.c b/termo.c
index 469af1d..d72a4f5 100644
--- a/termo.c
+++ b/termo.c
@@ -425,12 +425,12 @@ termo_new (int fd, const char *encoding, int flags)
termo_set_flags (tk, flags);
const char *term = getenv ("TERM");
- if (termo_init (tk, term, encoding)
- && termo_start (tk))
+ if (!termo_init (tk, term, encoding))
+ free (tk);
+ else if (!(flags & TERMO_FLAG_NOSTART) && !termo_start (tk))
+ termo_free (tk);
+ else
return tk;
-
- // FIXME: resource leak on termo_start() failure
- free (tk);
return NULL;
}
@@ -445,13 +445,12 @@ termo_new_abstract (const char *term, const char *encoding, int flags)
termo_set_flags (tk, flags);
if (!termo_init (tk, term, encoding))
- {
free (tk);
- return NULL;
- }
-
- termo_start (tk);
- return tk;
+ else if (!(flags & TERMO_FLAG_NOSTART) && !termo_start (tk))
+ termo_free (tk);
+ else
+ return tk;
+ return NULL;
}
void