[VDPAU] [PATCH] Don't leak the vdpau_wrapper.cfg file pointer
Aaron Plattner
aplattner at nvidia.com
Mon Jul 22 14:14:05 PDT 2013
init_config opens vdpau_wrapper.cfg and reads its contents, but never closes it.
This causes a file descriptor leak if libvdpau is unloaded and reloaded.
Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
---
src/vdpau_wrapper.c | 2 ++
test/dlclose.c | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
index d847a87..0130597 100644
--- a/src/vdpau_wrapper.c
+++ b/src/vdpau_wrapper.c
@@ -357,6 +357,8 @@ void init_config(void)
_disable_flash_pq_bg_color = atoi(param);
}
}
+
+ fclose(fp);
}
void init_fixes(void)
diff --git a/test/dlclose.c b/test/dlclose.c
index 14a957f..e2295c9 100644
--- a/test/dlclose.c
+++ b/test/dlclose.c
@@ -1,3 +1,4 @@
+#include <dirent.h>
#include <dlfcn.h>
#include <stdio.h>
#include <vdpau/vdpau.h>
@@ -8,11 +9,32 @@
#define FAIL 1
#define SKIP 77
+static int countOpenFDs(void)
+{
+ DIR *dir = opendir("/proc/self/fd");
+ struct dirent *ent;
+ int count = 0;
+
+ if (!dir) {
+ fprintf(stderr, "Couldn't open /proc/self/fd; skipping file descriptor "
+ "leak test\n");
+ return 0;
+ }
+
+ while (ent = readdir(dir)) {
+ count++;
+ }
+
+ closedir(dir);
+ return count;
+}
+
int main()
{
// Work around a bug in libXext: dlclosing it after it has registered the
// Generic Event Extension causes an identical bug to the one this program
// is trying to test for.
+ int nOpenFDs = countOpenFDs();
void *libXext = dlopen("libXext.so.6", RTLD_LAZY);
void *libvdpau = dlopen("../src/.libs/libvdpau.so", RTLD_LAZY);
Display *dpy = XOpenDisplay(NULL);
@@ -60,5 +82,11 @@ int main()
dlclose(libvdpau);
XCloseDisplay(dpy);
+ // Make sure no file descriptors were leaked.
+ if (countOpenFDs() != nOpenFDs) {
+ fprintf(stderr, "Mismatch in the number of open file descriptors!\n");
+ return FAIL;
+ }
+
return PASS;
}
--
1.8.3.3
More information about the VDPAU
mailing list