Windows: cm_ConnByServer increment under lock
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 31 Oct 2012 16:04:50 +0000 (12:04 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 31 Oct 2012 22:17:37 +0000 (15:17 -0700)
Incrementing the cm_conn.refCount must be performed while holding
the cm_connLock in order to prevent cm_GCConnections() from
seeing an in-use object as having a zero count.

Change-Id: Ifaa755ef0f04f3bf64223434dfc518bc73d01d4d
Reviewed-on: http://gerrit.openafs.org/8347
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/cm_conn.c

index e625db0..195c4e1 100644 (file)
@@ -1592,6 +1592,7 @@ long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, afs_uint32 replicat
                 break;
         }
         if (tcp) {
+            InterlockedIncrement(&tcp->refCount);
             lock_ReleaseWrite(&cm_connLock);
             goto haveconn;
         }
@@ -1610,10 +1611,10 @@ long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, afs_uint32 replicat
         lock_ReleaseWrite(&cm_connLock);
         lock_ReleaseMutex(&userp->mx);
     } else {
+        InterlockedIncrement(&tcp->refCount);
         lock_ReleaseRead(&cm_connLock);
       haveconn:
         lock_ReleaseMutex(&userp->mx);
-        InterlockedIncrement(&tcp->refCount);
 
         lock_ObtainMutex(&tcp->mx);
         if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||