launcher: Don't leak tty file descriptor on error
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 9 Oct 2013 18:19:11 +0000 (11:19 -0700)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 10 Oct 2013 23:50:18 +0000 (16:50 -0700)
src/launcher-util.c

index d90271f..8ab61f1 100644 (file)
@@ -275,7 +275,7 @@ setup_tty(struct weston_launcher *launcher, int tty)
                weston_log("%s not a vt\n", tty_device);
                weston_log("if running weston from ssh, "
                           "use --tty to specify a tty\n");
-               return -1;
+               goto err_close;
        }
 
        ret = ioctl(launcher->tty, KDGETMODE, &kd_mode);
@@ -286,7 +286,7 @@ setup_tty(struct weston_launcher *launcher, int tty)
        if (kd_mode != KD_TEXT) {
                weston_log("%s is already in graphics mode, "
                           "is another display server running?\n", tty_device);
-               return -1;
+               goto err_close;
        }
 
        ret = ioctl(launcher->tty, VT_ACTIVATE, minor(buf.st_rdev));
@@ -297,19 +297,19 @@ setup_tty(struct weston_launcher *launcher, int tty)
 
        if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) {
                weston_log("failed to read keyboard mode: %m\n");
-               return -1;
+               goto err_close;
        }
 
        if (ioctl(launcher->tty, KDSKBMUTE, 1) &&
            ioctl(launcher->tty, KDSKBMODE, K_OFF)) {
                weston_log("failed to set K_OFF keyboard mode: %m\n");
-               return -1;
+               goto err_close;
        }
 
        ret = ioctl(launcher->tty, KDSETMODE, KD_GRAPHICS);
        if (ret) {
                weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
-               return -1;
+               goto err_close;
        }
 
        mode.mode = VT_PROCESS;
@@ -317,16 +317,20 @@ setup_tty(struct weston_launcher *launcher, int tty)
        mode.acqsig = SIGUSR1;
        if (ioctl(launcher->tty, VT_SETMODE, &mode) < 0) {
                weston_log("failed to take control of vt handling\n");
-               return -1;
+               goto err_close;
        }
 
        loop = wl_display_get_event_loop(launcher->compositor->wl_display);
        launcher->vt_source =
                wl_event_loop_add_signal(loop, SIGUSR1, vt_handler, launcher);
        if (!launcher->vt_source)
-               return -1;
+               goto err_close;
 
        return 0;
+
+ err_close:
+       close(launcher->tty);
+       return -1;
 }
 
 int