* Free a cred structure. Throws away space when ref count gets to 0. */
| 2031 | * Free a cred structure. Throws away space when ref count gets to 0. |
| 2032 | */ |
| 2033 | void |
| 2034 | crfree(struct ucred *cr) |
| 2035 | { |
| 2036 | struct thread *td; |
| 2037 | |
| 2038 | td = curthread; |
| 2039 | if (__predict_true(td->td_realucred == cr)) { |
| 2040 | KASSERT(cr->cr_users > 0, ("%s: users %d not > 0 on cred %p", |
| 2041 | __func__, cr->cr_users, cr)); |
| 2042 | td->td_ucredref--; |
| 2043 | return; |
| 2044 | } |
| 2045 | mtx_lock(&cr->cr_mtx); |
| 2046 | KASSERT(cr->cr_users >= 0, ("%s: users %d not >= 0 on cred %p", |
| 2047 | __func__, cr->cr_users, cr)); |
| 2048 | cr->cr_ref--; |
| 2049 | if (cr->cr_users > 0) { |
| 2050 | mtx_unlock(&cr->cr_mtx); |
| 2051 | return; |
| 2052 | } |
| 2053 | KASSERT(cr->cr_ref >= 0, ("%s: ref %d not >= 0 on cred %p", |
| 2054 | __func__, cr->cr_ref, cr)); |
| 2055 | if (cr->cr_ref > 0) { |
| 2056 | mtx_unlock(&cr->cr_mtx); |
| 2057 | return; |
| 2058 | } |
| 2059 | crfree_final(cr); |
| 2060 | } |
| 2061 | |
| 2062 | static void |
| 2063 | crfree_final(struct ucred *cr) |
no test coverage detected