Index: nfs_commonkrpc.c =================================================================== --- nfs_commonkrpc.c (revision 228700) +++ nfs_commonkrpc.c (working copy) @@ -186,9 +186,9 @@ * Use the credential in nr_cred, if not NULL. */ if (nrp->nr_cred != NULL) - td->td_ucred = nrp->nr_cred; + td->td_ucred = NFSHOLDCRED(nrp->nr_cred); else - td->td_ucred = cred; + td->td_ucred = NFSHOLDCRED(cred); saddr = nrp->nr_nam; if (saddr->sa_family == AF_INET) @@ -220,10 +220,8 @@ saddr = NFSSOCKADDR(nrp->nr_nam, struct sockaddr *); error = socreate(saddr->sa_family, &so, nrp->nr_sotype, nrp->nr_soproto, td->td_ucred, td); - if (error) { - td->td_ucred = origcred; + if (error) goto out; - } do { if (error != 0 && pktscale > 2) pktscale--; @@ -251,10 +249,8 @@ error = soreserve(so, sndreserve, rcvreserve); } while (error != 0 && pktscale > 2); soclose(so); - if (error) { - td->td_ucred = origcred; + if (error) goto out; - } client = clnt_reconnect_create(nconf, saddr, nrp->nr_prog, nrp->nr_vers, sndreserve, rcvreserve); @@ -305,10 +301,11 @@ mtx_unlock(&nrp->nr_mtx); } +out: /* Restore current thread's credentials. */ + NFSFREECRED(td->td_ucred); td->td_ucred = origcred; -out: NFSEXITCODE(error); return (error); } Index: nfsport.h =================================================================== --- nfsport.h (revision 228700) +++ nfsport.h (working copy) @@ -515,6 +515,7 @@ #define NFSNEWCRED(c) (crdup(c)) #define NFSPROCCRED(p) ((p)->td_ucred) #define NFSFREECRED(c) (crfree(c)) +#define NFSHOLDCRED(c) (crhold(c)) #define NFSUIOPROC(u, p) ((u)->uio_td = NULL) #define NFSPROCP(p) ((p)->td_proc)