only use tpreserved when it's not NULL #2132

This commit is contained in:
nick black 2021-08-31 15:51:45 -04:00
parent 0fd2fe7ce1
commit 0ee5ba4ffe
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 5 additions and 3 deletions

View File

@ -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);

View File

@ -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);