Print this page
Zone ID only matches once, don't loop after a match
Two NLM fixes: use zone_kcred() and plug cl_auth leaks
        
@@ -841,40 +841,48 @@
         /*
          * Create an RPC handle that'll be used for communication with local
          * statd using the status monitor protocol.
          */
         error = clnt_tli_kcreate(&nsm->ns_knc, &nsm->ns_addr, SM_PROG, SM_VERS,
-            0, NLM_RPC_RETRIES, kcred, &nsm->ns_handle);
+            0, NLM_RPC_RETRIES, zone_kcred(), &nsm->ns_handle);
         if (error != 0)
                 goto error;
 
         /*
          * Create an RPC handle that'll be used for communication with the
          * local statd using the address registration protocol.
          */
         error = clnt_tli_kcreate(&nsm->ns_knc, &nsm->ns_addr, NSM_ADDR_PROGRAM,
-            NSM_ADDR_V1, 0, NLM_RPC_RETRIES, kcred, &nsm->ns_addr_handle);
+            NSM_ADDR_V1, 0, NLM_RPC_RETRIES, zone_kcred(),
+            &nsm->ns_addr_handle);
         if (error != 0)
                 goto error;
 
         sema_init(&nsm->ns_sem, 1, NULL, SEMA_DEFAULT, NULL);
         return (0);
 
 error:
         kmem_free(nsm->ns_addr.buf, nsm->ns_addr.maxlen);
-        if (nsm->ns_handle)
+        if (nsm->ns_handle) {
+                ASSERT(nsm->ns_handle->cl_auth != NULL);
+                auth_destroy(nsm->ns_handle->cl_auth);
                 CLNT_DESTROY(nsm->ns_handle);
+        }
 
         return (error);
 }
 
 static void
 nlm_nsm_fini(struct nlm_nsm *nsm)
 {
         kmem_free(nsm->ns_addr.buf, nsm->ns_addr.maxlen);
+        if (nsm->ns_addr_handle->cl_auth != NULL)
+                auth_destroy(nsm->ns_addr_handle->cl_auth);
         CLNT_DESTROY(nsm->ns_addr_handle);
         nsm->ns_addr_handle = NULL;
+        if (nsm->ns_handle->cl_auth != NULL)
+                auth_destroy(nsm->ns_handle->cl_auth);
         CLNT_DESTROY(nsm->ns_handle);
         nsm->ns_handle = NULL;
         sema_destroy(&nsm->ns_sem);
 }
 
@@ -2625,14 +2633,22 @@
 {
         struct nlm_globals *g;
 
         rw_enter(&lm_lck, RW_READER);
         TAILQ_FOREACH(g, &nlm_zones_list, nlm_link) {
-                if (g->nlm_zoneid != exi->exi_zoneid)
-                        continue;
+                if (g->nlm_zoneid == exi->exi_zoneid) {
+                        /*
+                         * NOTE: If we want to drop lm_lock before
+                         * calling nlm_zone_unexport(), we should break,
+                         * and have a post-rw_exit() snippit like:
+                         *      if (g != NULL)
+                         *              nlm_zone_unexport(g, exi);
+                         */
                 nlm_zone_unexport(g, exi);
+                        break; /* Only going to match once! */
         }
+        }
         rw_exit(&lm_lck);
 }
 
 /*
  * Allocate new unique sysid.
@@ -2800,11 +2816,11 @@
 
 static void
 nlm_nsm_clnt_init(CLIENT *clnt, struct nlm_nsm *nsm)
 {
         (void) clnt_tli_kinit(clnt, &nsm->ns_knc, &nsm->ns_addr, 0,
-            NLM_RPC_RETRIES, kcred);
+            NLM_RPC_RETRIES, zone_kcred());
 }
 
 static void
 nlm_netbuf_to_netobj(struct netbuf *addr, int *family, netobj *obj)
 {