rpcrt4: Always protect ref access for connections associated with protseq in RPCRT4_ReleaseConnection.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Jacek Caban 2017-08-02 15:51:09 +02:00 committed by Alexandre Julliard
parent bb256b4f21
commit 2d9e894d28
1 changed files with 11 additions and 7 deletions

View File

@ -3382,20 +3382,24 @@ RpcConnection *RPCRT4_GrabConnection(RpcConnection *connection)
void RPCRT4_ReleaseConnection(RpcConnection *connection)
{
LONG ref = InterlockedDecrement(&connection->ref);
LONG ref;
if (!ref && connection->protseq)
/* protseq stores a list of active connections, but does not own references to them.
* It may need to grab a connection from the list, which could lead to a race if
* connection is being released, but not yet removed from the list. We handle that
* by synchronizing on CS here. */
if (connection->protseq)
{
/* protseq stores a list of active connections, but does not own references to them.
* It may need to grab a connection from the list, which could lead to a race if
* connection is being released, but not yet removed from the list. We handle that
* by synchronizing on CS here. */
EnterCriticalSection(&connection->protseq->cs);
ref = connection->ref;
ref = InterlockedDecrement(&connection->ref);
if (!ref)
list_remove(&connection->protseq_entry);
LeaveCriticalSection(&connection->protseq->cs);
}
else
{
ref = InterlockedDecrement(&connection->ref);
}
TRACE("%p ref=%u\n", connection, ref);