Permalink
Browse files

In case of initialization failure file descriptors should be closed.

  • Loading branch information...
ssharunas committed Aug 12, 2012
1 parent 6e8871d commit b61c209bd1ba8d1f07db718b12ba13eaf067d414
Showing with 18 additions and 3 deletions.
  1. +18 −3 src/termbox.c
View
@@ -81,17 +81,32 @@ int tb_init(void)
out = open("/dev/tty", O_WRONLY);
in = fopen("/dev/tty", "r");
- if (out == -1 || !in)
+ if (out == -1 || !in) {
+ if(out != -1)
+ close(out);
+
+ if(in)
+ fclose(in);
+
return TB_EFAILED_TO_OPEN_TTY;
+ }
out_fileno = out;
in_fileno = fileno(in);
- if (init_term() < 0)
+ if (init_term() < 0) {
+ close(out);
+ fclose(in);
+
return TB_EUNSUPPORTED_TERMINAL;
+ }
+
+ if (pipe(winch_fds) < 0) {
+ close(out);
+ fclose(in);
- if (pipe(winch_fds) < 0)
return TB_EPIPE_TRAP_ERROR;
+ }
struct sigaction sa;
sa.sa_handler = sigwinch_handler;

0 comments on commit b61c209

Please sign in to comment.