pf: remove NULL check before uma_zfree()

uma_zfree() can be called on a NULL pointer. Simplify the pf code a
little by removing the redundant checks.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
This commit is contained in:
Kristof Provost 2023-05-04 17:20:02 +02:00
parent 0d66206fff
commit bf206a1db2
3 changed files with 10 additions and 20 deletions

View File

@ -649,10 +649,8 @@ pfsync_state_import(struct pfsync_state *sp, int flags)
error = ENOMEM;
if (skw == sks)
sks = NULL;
if (skw != NULL)
uma_zfree(V_pf_state_key_z, skw);
if (sks != NULL)
uma_zfree(V_pf_state_key_z, sks);
uma_zfree(V_pf_state_key_z, skw);
uma_zfree(V_pf_state_key_z, sks);
cleanup_state: /* pf_state_insert() frees the state keys. */
if (st) {

View File

@ -4541,10 +4541,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction,
return (action);
}
} else {
if (sk != NULL)
uma_zfree(V_pf_state_key_z, sk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, nk);
}
/* copy back packet headers if we performed NAT operations */
@ -4570,10 +4568,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction,
free(ri, M_PF_RULE_ITEM);
}
if (sk != NULL)
uma_zfree(V_pf_state_key_z, sk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, nk);
return (PF_DROP);
}
@ -4812,10 +4808,8 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
return (PF_PASS);
csfailed:
if (sk != NULL)
uma_zfree(V_pf_state_key_z, sk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, nk);
if (sn != NULL) {
PF_SRC_NODE_LOCK(sn);

View File

@ -1576,10 +1576,8 @@ pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd,
void
pf_normalize_tcp_cleanup(struct pf_kstate *state)
{
if (state->src.scrub)
uma_zfree(V_pf_state_scrub_z, state->src.scrub);
if (state->dst.scrub)
uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
uma_zfree(V_pf_state_scrub_z, state->src.scrub);
uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
/* Someday... flush the TCP segment reassembly descriptors. */
}