[PATCH] api: use mutex when removing instance on close adapter
Jean-Alexandre CHRONE
Jean-Alexandre.CHRONE at stormshield.eu
Fri Mar 6 10:05:15 UTC 2026
Hello,
Did anyone have the same issue as mentioned in the earlier message?
We encountered it any time we had to reset an adapter multiple times in a short lapse of time.
Best Regards,
Jean-Alexandre
-----Original message-----
>From 298267d3ead7110880a5dc0f5d0e8822600d30c0 Mon Sep 17 00:00:00 2001
From: "jean-alexandre.chrone" <jean-alexandre.chrone at stormshield.eu>
Date: Mon, 2 Feb 2026 15:24:12 +0100
Subject: [PATCH] api: use mutex when removing instance on close adapter
on successive create and close there might be some error logged
---
api/adapter.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/api/adapter.c b/api/adapter.c index 0dd8c42..042645c 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -158,7 +158,8 @@ VOID AdapterCleanupOrphanedDevices(VOID)
continue;
}
ULONG Status, Code;
- if (CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0) == CR_SUCCESS && !(Status & DN_HAS_PROBLEM))
+ CONFIGRET Ret = CM_Get_DevNode_Status(&Status, &Code, DevInfoData.DevInst, 0);
+ if ((Ret == CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) || Ret ==
+ CR_NO_SUCH_DEVNODE)
continue;
DEVPROPTYPE PropType;
@@ -195,8 +196,16 @@ WintunCloseAdapter(WINTUN_ADAPTER *Adapter)
SwDeviceClose(Adapter->SwDevice);
if (Adapter->DevInfo)
{
+ HANDLE DeviceInstallationMutex = NamespaceTakeDeviceInstallationMutex();
+ if (DeviceInstallationMutex == NULL)
+ LOG_LAST_ERROR(L"Failed to take device installation
+ mutex");
+
if (!AdapterRemoveInstance(Adapter->DevInfo, &Adapter->DevInfoData))
LOG_LAST_ERROR(L"Failed to remove adapter when closing");
+
+ if (DeviceInstallationMutex != NULL)
+ NamespaceReleaseMutex(DeviceInstallationMutex);
+
SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
}
Free(Adapter);
--
2.52.0.windows.1
More information about the WireGuard
mailing list