Jinoh Kang (@iamahuman) commented about dlls/win32u/winstation.c:
static const WCHAR winsta0[] = {'W','i','n','S','t','a','0',0};
- shared_session = get_shared_session( FALSE );
Since `get_shared_session` returns the last `shared_session` value anyway, this is more-or-less equivalent to:
```c shared_session_release( get_shared_session( FALSE ) ); shared_session = shared_session_acquire( shared_session ); ```
which leaks a reference.
In principle, you shouldn't overwrite a reference-counted pointer variable before releasing its old object, **even if the old one is the same as the new one.**[^1]
Here, `get_shared_session` already writes to `shared_session`. To re-assign `shared_session`, you need to first release it.
```suggestion:-0+0 struct shared_session *tmp = get_shared_session( FALSE ); // acquire reference
// get_shared_session() has assigned to the `shared_sesion` variable. // We need to release it first. shared_session_release( shared_session );
// Now, the reference associated with `shared_session` is now gone. We can safely overwrite it without leaking: shared_session = tmp; // transfer ownership to the variable ```
Since `shared_session == tmp`, the above reduces to:
```suggestion:-0+0 shared_session_release( get_shared_session( FALSE ) ); ```
[^1]: Except you probably want to skip the assign-the-same-value noop operation altogether.