wintun: take mutex first always
This prevents an ABA deadlock with setupapi's internal locks.
This commit is contained in:
parent
f3dba4c194
commit
73d3bd9cd5
@ -196,6 +196,15 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
|
|||||||
// interesting complications with its usage. This function returns the network
|
// interesting complications with its usage. This function returns the network
|
||||||
// interface ID and a flag if reboot is required.
|
// interface ID and a flag if reboot is required.
|
||||||
func (pool Pool) CreateInterface(ifname string, requestedGUID *windows.GUID) (wintun *Interface, rebootRequired bool, err error) {
|
func (pool Pool) CreateInterface(ifname string, requestedGUID *windows.GUID) (wintun *Interface, rebootRequired bool, err error) {
|
||||||
|
mutex, err := pool.takeNameMutex()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
windows.ReleaseMutex(mutex)
|
||||||
|
windows.CloseHandle(mutex)
|
||||||
|
}()
|
||||||
|
|
||||||
// Create an empty device info set for network adapter device class.
|
// Create an empty device info set for network adapter device class.
|
||||||
devInfoList, err := setupapi.SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
|
devInfoList, err := setupapi.SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -281,15 +290,6 @@ func (pool Pool) CreateInterface(ifname string, requestedGUID *windows.GUID) (wi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex, err := pool.takeNameMutex()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
windows.ReleaseMutex(mutex)
|
|
||||||
windows.CloseHandle(mutex)
|
|
||||||
}()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// The interface failed to install, or the interface ID was unobtainable. Clean-up.
|
// The interface failed to install, or the interface ID was unobtainable. Clean-up.
|
||||||
|
Loading…
Reference in New Issue
Block a user