diff options
author | Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> | 2022-02-22 10:41:20 +0100 |
---|---|---|
committer | Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> | 2022-02-22 15:50:50 +0100 |
commit | 5f3cfa485eb46902e55c6b96c80dc8c57ddf3b43 (patch) | |
tree | e8b9d7488332ff8ca589c6b33b59ecb9c4ec1eba /lib/igt_core.c | |
parent | 0696e8b9cd5f0e112f4d5459e03a1d4d6bb95d9a (diff) |
lib: Use safe wrappers around libpciaccess initialization functions
Multiple calls to igt functions using pci_system_init() provided by
libpciaccess result in memory leaking if not followed by its counterpart
pci_system_cleanup() before next use. On the other hand, calling
pci_system_cleanup() can affect other users which still depend on global
data initialized by pci_system_init().
Introduce safe IGT wrappers around those libpciaccess functions and use
those wrappers in IGT library and tests.
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
[jkrzyszt: shorten excessive long name of hidden variable (Chris)]
Reviewed-by: Chris Wilson <chris.p.wilson@intel.com>
Diffstat (limited to 'lib/igt_core.c')
-rw-r--r-- | lib/igt_core.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c index ab27a24d..f2c701de 100644 --- a/lib/igt_core.c +++ b/lib/igt_core.c @@ -3070,3 +3070,23 @@ err: return -1; } + +/* IGT wrappers around libpciaccess init/cleanup functions */ + +static void pci_system_exit_handler(int sig) +{ + pci_system_cleanup(); +} + +static void __pci_system_init(void) +{ + if (!igt_warn_on_f(pci_system_init(), "Could not initialize libpciaccess global data\n")) + igt_install_exit_handler(pci_system_exit_handler); +} + +int igt_pci_system_init(void) +{ + static pthread_once_t once_control = PTHREAD_ONCE_INIT; + + return pthread_once(&once_control, __pci_system_init); +} |