summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-27 10:54:49 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-27 11:59:15 -0600
commit26fb615b11a581e399771448c5ae19a01e7be7f2 (patch)
tree8be9e3c85197e2f1e2f15fd19de16bd78d10a1d7
parent7fbb24afaac9c89c98db89f7773ce82c919c520c (diff)
wintun: cleanup earlier
-rw-r--r--tun/wintun/wintun_windows.go39
1 files changed, 20 insertions, 19 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index f5d42eb..3566a76 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -257,6 +257,26 @@ func CreateInterface(requestedGUID *windows.GUID) (wintun *Wintun, rebootRequire
return
}
+ defer func() {
+ if err != nil {
+ // The interface failed to install, or the interface ID was unobtainable. Clean-up.
+ removeDeviceParams := setupapi.RemoveDeviceParams{
+ ClassInstallHeader: *setupapi.MakeClassInstallHeader(setupapi.DIF_REMOVE),
+ Scope: setupapi.DI_REMOVEDEVICE_GLOBAL,
+ }
+
+ // Set class installer parameters for DIF_REMOVE.
+ if devInfoList.SetClassInstallParams(deviceData, &removeDeviceParams.ClassInstallHeader, uint32(unsafe.Sizeof(removeDeviceParams))) == nil {
+ // Call appropriate class installer.
+ if devInfoList.CallClassInstaller(setupapi.DIF_REMOVE, deviceData) == nil {
+ rebootRequired = rebootRequired || checkReboot(devInfoList, deviceData)
+ }
+ }
+
+ wintun = nil
+ }
+ }()
+
// Call appropriate class installer.
err = devInfoList.CallClassInstaller(setupapi.DIF_REGISTERDEVICE, deviceData)
if err != nil {
@@ -293,25 +313,6 @@ func CreateInterface(requestedGUID *windows.GUID) (wintun *Wintun, rebootRequire
// Install interfaces if any. (Ignore errors)
devInfoList.CallClassInstaller(setupapi.DIF_INSTALLINTERFACES, deviceData)
- defer func() {
- if err != nil {
- // The interface failed to install, or the interface ID was unobtainable. Clean-up.
- removeDeviceParams := setupapi.RemoveDeviceParams{
- ClassInstallHeader: *setupapi.MakeClassInstallHeader(setupapi.DIF_REMOVE),
- Scope: setupapi.DI_REMOVEDEVICE_GLOBAL,
- }
-
- // Set class installer parameters for DIF_REMOVE.
- if devInfoList.SetClassInstallParams(deviceData, &removeDeviceParams.ClassInstallHeader, uint32(unsafe.Sizeof(removeDeviceParams))) == nil {
- // Call appropriate class installer.
- if devInfoList.CallClassInstaller(setupapi.DIF_REMOVE, deviceData) == nil {
- rebootRequired = rebootRequired || checkReboot(devInfoList, deviceData)
- }
- }
-
- wintun = nil
- }
- }()
// Install the device.
err = devInfoList.CallClassInstaller(setupapi.DIF_INSTALLDEVICE, deviceData)