drm: ensure drm_fd is closed if open fails

At the moment we open the drm fd right away, then proceed to
check the terminal.  If the terminal doesn't meet specs, we
fail the open call but neglect to close the drm_fd.

This commit fixes the code such that we don't leave the drm
fd open inadvertently.
This commit is contained in:
Ray Strode 2018-06-01 14:41:32 -04:00
parent bf560986f0
commit 8aa3b01b33

View file

@ -145,6 +145,7 @@ static bool reset_scan_out_buffer_if_needed (ply_renderer_backend_t *backend,
ply_renderer_head_t *head);
static void flush_head (ply_renderer_backend_t *backend,
ply_renderer_head_t *head);
static void close_device (ply_renderer_backend_t *backend);
static bool
ply_renderer_buffer_map (ply_renderer_backend_t *backend,
@ -880,13 +881,13 @@ open_device (ply_renderer_backend_t *backend)
if (!ply_terminal_open (backend->terminal)) {
ply_trace ("could not open terminal: %m");
return false;
goto failed;
}
if (!ply_terminal_is_vt (backend->terminal)) {
ply_trace ("terminal is not a VT");
ply_terminal_close (backend->terminal);
return false;
goto failed;
}
ply_terminal_watch_for_active_vt_change (backend->terminal,
@ -895,6 +896,10 @@ open_device (ply_renderer_backend_t *backend)
backend);
return true;
failed:
close_device (backend);
return false;
}
static void