Rémi Bernon (@rbernon) commented about dlls/ntdll/unix/sync.c:
/* someone beat us to it */
if (needs_close) close( fd );
NtClose( handle );
}
/* otherwise don't close the device */
}
else
{
InterlockedCompareExchange( &device, -1, -2 );
NtClose( handle );
}
}
else
{
InterlockedCompareExchange( &device, -1, -2 );
}
The comment above still applies and I don't think we should be leaking the handle or using the fd cache her. Then we don't need to keep or leak the handle and this could still thus be simplified to:
```suggestion:-21+0 if (ret || server_get_unix_fd( handle, 0, &fd, &needs_close, NULL, NULL )) fd = -1; if (InterlockedCompareExchange( &device, fd, -2 ) != -2 && fd != -1) close( fd ); /* someone beat us to it */ if (!ret) NtClose( handle ); ```
Optionally with an `assert( fd == -1 || needs_close );` if you think it's worth being careful but I don't think it's necessary.