RE: [PATCH] api: use mutex when removing instance on close adapter
Jean-Alexandre CHRONE <[email protected]> Fri, 6 Mar 2026 10:05:15 +0000
| Newsgroups | com.zx2c4.lists.wireguard |
|---|---|
| Message-ID | <[email protected]> |
Hello,=20 Did anyone have the same issue as mentioned in the earlier message?=20 We encountered it any time we had to reset an adapter multiple times in a s= hort lapse of time. Best Regards, Jean-Alexandre -----Original message----- From 298267d3ead7110880a5dc0f5d0e8822600d30c0 Mon Sep 17 00:00:00 2001 From: "jean-alexandre.chrone" <[email protected]> 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) = =3D=3D CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) + CONFIGRET Ret =3D CM_Get_DevNode_Status(&Status, &Code, DevInfoDat= a.DevInst, 0); + if ((Ret =3D=3D CR_SUCCESS && !(Status & DN_HAS_PROBLEM)) || Ret = =3D=3D=20 + CR_NO_SUCH_DEVNODE) continue; =20 DEVPROPTYPE PropType; @@ -195,8 +196,16 @@ WintunCloseAdapter(WINTUN_ADAPTER *Adapter) SwDeviceClose(Adapter->SwDevice); if (Adapter->DevInfo) { + HANDLE DeviceInstallationMutex =3D NamespaceTakeDeviceInstallation= Mutex(); + if (DeviceInstallationMutex =3D=3D NULL) + LOG_LAST_ERROR(L"Failed to take device installation=20 + mutex"); + if (!AdapterRemoveInstance(Adapter->DevInfo, &Adapter->DevInfoData= )) LOG_LAST_ERROR(L"Failed to remove adapter when closing"); + + if (DeviceInstallationMutex !=3D NULL) + NamespaceReleaseMutex(DeviceInstallationMutex); + SetupDiDestroyDeviceInfoList(Adapter->DevInfo); } Free(Adapter); -- 2.52.0.windows.1