dns-and-server-ref-counts-20040530
[openafs.git] / src / WINNT / afsd / cm_server.c
index 71cfc64..77707e1 100644 (file)
@@ -390,6 +390,34 @@ void cm_RandomizeServer(cm_serverRef_t** list)
     lock_ReleaseWrite(&cm_serverLock);
 }
 
+void cm_FreeServer(cm_server_t* server)
+{
+    lock_ObtainWrite(&cm_serverLock);
+    if (--(server->refCount) == 0)
+    {
+        /* we need to check to ensure that all of the connections
+         * for this server have a 0 refCount; otherwise, they will
+         * not be garbage collected 
+         */
+        cm_GCConnections(&server);  /* connsp */
+
+        lock_FinalizeMutex(&server->mx);
+        if ( cm_allServersp == server )
+            cm_allServersp = server->allNextp;
+        else {
+            cm_server_t *tsp;
+
+            for(tsp = cm_allServersp; tsp->allNextp; tsp=tsp->allNextp) {
+                if ( tsp->allNextp == server ) {
+                    tsp->allNextp = server->allNextp;
+                    break;
+                }
+            }
+        }
+    }
+    lock_ReleaseWrite(&cm_serverLock);
+}
+
 void cm_FreeServerList(cm_serverRef_t** list)
 {
     cm_serverRef_t  *current = *list;
@@ -399,9 +427,10 @@ void cm_FreeServerList(cm_serverRef_t** list)
 
     while (current)
     {
-          next = current->next;
-          free(current);
-          current = next;
+        next = current->next;
+        cm_FreeServer(current->server);
+        free(current);
+        current = next;
     }
   
     lock_ReleaseWrite(&cm_serverLock);