summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Stark <gavin@gstark.com>2020-05-20 17:23:14 -0400
committerXinfengZhang <carl.zhang@intel.com>2020-06-09 22:53:31 +0800
commitb4e690fb33cbfb35a12cffe4b655a4045f71aa82 (patch)
treeec478d2552f024f5d14d81fb9df1d5d30b8db169
parenta307f426f82fa495c7b14e15e625614f16788d9c (diff)
downloadlibva-b4e690fb33cbfb35a12cffe4b655a4045f71aa82.tar.gz
Fixes file descriptor leak
If code calls va_isDRI2Connected multiple times there is no protection against calling open(device_name, O_RDWR) again and losing the reference to the original file descriptor. A recent change (bc8a12) calls the method twice each time libva is initialized, thus causing a leak of device file descriptors. This change moves the initializing of the fd and auth_type to the creation of the dri_state and then checks to see if they have already been initialized. If so, the method va_isDRIConnected returns true and fills in driver_name.
-rw-r--r--va/x11/dri2_util.c7
-rw-r--r--va/x11/va_x11.c3
2 files changed, 8 insertions, 2 deletions
diff --git a/va/x11/dri2_util.c b/va/x11/dri2_util.c
index e383db1..2218adf 100644
--- a/va/x11/dri2_util.c
+++ b/va/x11/dri2_util.c
@@ -182,8 +182,7 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
char *device_name = NULL;
drm_magic_t magic;
*driver_name = NULL;
- dri_state->base.fd = -1;
- dri_state->base.auth_type = VA_NONE;
+
if (!VA_DRI2QueryExtension(ctx->native_dpy, &event_base, &error_base))
goto err_out;
@@ -195,6 +194,9 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
driver_name, &device_name))
goto err_out;
+ if ((dri_state->base.fd != -1) && (dri_state->base.auth_type != VA_NONE))
+ goto success_out;
+
dri_state->base.fd = open(device_name, O_RDWR);
if (dri_state->base.fd < 0)
@@ -215,6 +217,7 @@ va_isDRI2Connected(VADriverContextP ctx, char **driver_name)
dri_state->close = dri2Close;
gsDRI2SwapAvailable = (minor >= 2);
+success_out:
Xfree(device_name);
return True;
diff --git a/va/x11/va_x11.c b/va/x11/va_x11.c
index cb23168..453ed46 100644
--- a/va/x11/va_x11.c
+++ b/va/x11/va_x11.c
@@ -287,6 +287,9 @@ VADisplay vaGetDisplay (
return NULL;
}
+ dri_state->base.fd = -1;
+ dri_state->base.auth_type = VA_NONE;
+
pDriverContext->drm_state = dri_state;
return (VADisplay)pDisplayContext;