Patch for libpciaccess 0.13.2 to "reference count" init/cleanup calls. --- a/src/common_init.c 2014-09-14 03:17:38.628195344 +0400 +++ b/src/common_init.c 2014-09-14 03:19:31.402246351 +0400 @@ -36,6 +36,7 @@ #include "pciaccess_private.h" _pci_hidden struct pci_system * pci_sys; +static pci_sys_refcnt = 0; /** * Initialize the PCI subsystem for access. @@ -52,6 +53,11 @@ pci_system_init( void ) { int err = ENOSYS; + if ( pci_sys_refcnt > 0 ) { + pci_sys_refcnt++; + return 0; + } + #ifdef linux err = pci_system_linux_sysfs_create(); #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) @@ -66,6 +72,10 @@ pci_system_init( void ) err = pci_system_x86_create(); #endif + if ( pci_sys ) { + pci_sys_refcnt = 1; + } + return err; } @@ -91,6 +101,9 @@ pci_system_cleanup( void ) if ( pci_sys == NULL ) { return; + } else if ( pci_sys_refcnt > 1 ) { + pci_sys_refcnt--; + return; } pci_io_cleanup(); @@ -123,4 +136,5 @@ pci_system_cleanup( void ) free( pci_sys ); pci_sys = NULL; + pci_sys_refcnt = 0; }