From 0ee5ba4ffe133820f27987b940a26f1bdc77d716 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 31 Aug 2021 15:51:45 -0400 Subject: [PATCH] only use tpreserved when it's not NULL #2132 --- src/lib/notcurses.c | 6 ++++-- src/lib/termdesc.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index fffdb2816..1c75b6f70 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1258,9 +1258,11 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ err: logpanic("Alas, you will not be going to space today.\n"); - // FIXME looks like we have some memory leaks on this error path? fbuf_free(&ret->rstate.f); - (void)tcsetattr(ret->tcache.ttyfd, TCSAFLUSH, ret->tcache.tpreserved); + if(ret->tcache.tpreserved){ + (void)tcsetattr(ret->tcache.ttyfd, TCSAFLUSH, ret->tcache.tpreserved); + free(ret->tcache.tpreserved); + } drop_signals(ret); del_curterm(cur_term); pthread_mutex_destroy(&ret->stats.lock); diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 4f2356f03..5cfc27915 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -921,7 +921,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut return 0; err: - if(ti->ttyfd >= 0){ + if(ti->tpreserved){ tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved); } free(ti->tpreserved);