diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-10-02 18:16:53 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-10-02 18:16:53 +0200 |
commit | c74c89e0281169412051a14a32b76729b53f0001 (patch) | |
tree | 44904a00e652a0f4db036607462fdb2088b84416 /src/codec_query | |
parent | fdc4bfe0d24f2d527b45e0b71b8f48f056a4d442 (diff) |
Proper error handling for fd cleanup in vaapi query
Diffstat (limited to 'src/codec_query')
-rw-r--r-- | src/codec_query/vaapi.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/codec_query/vaapi.c b/src/codec_query/vaapi.c index f919131..2c74d96 100644 --- a/src/codec_query/vaapi.c +++ b/src/codec_query/vaapi.c @@ -170,6 +170,7 @@ static bool get_supported_video_codecs(VADisplay va_dpy, gsr_supported_video_cod bool gsr_get_supported_video_codecs_vaapi(gsr_supported_video_codecs *video_codecs, const char *card_path, bool cleanup) { memset(video_codecs, 0, sizeof(*video_codecs)); bool success = false; + int drm_fd = -1; char render_path[128]; if(!gsr_card_path_get_render_path(card_path, render_path)) { @@ -177,7 +178,7 @@ bool gsr_get_supported_video_codecs_vaapi(gsr_supported_video_codecs *video_code goto done; } - const int drm_fd = open(render_path, O_RDWR); + drm_fd = open(render_path, O_RDWR); if(drm_fd == -1) { fprintf(stderr, "gsr error: gsr_get_supported_video_codecs_vaapi: failed to open device %s\n", render_path); goto done; @@ -193,8 +194,10 @@ bool gsr_get_supported_video_codecs_vaapi(gsr_supported_video_codecs *video_code } done: - if(cleanup) - close(drm_fd); + if(cleanup) { + if(drm_fd > 0) + close(drm_fd); + } return success; } |