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
+2 -4
View File
@@ -649,10 +649,8 @@ pfsync_state_import(struct pfsync_state *sp, int flags)
error = ENOMEM; error = ENOMEM;
if (skw == sks) if (skw == sks)
sks = NULL; sks = NULL;
if (skw != NULL) uma_zfree(V_pf_state_key_z, skw);
uma_zfree(V_pf_state_key_z, skw); uma_zfree(V_pf_state_key_z, sks);
if (sks != NULL)
uma_zfree(V_pf_state_key_z, sks);
cleanup_state: /* pf_state_insert() frees the state keys. */ cleanup_state: /* pf_state_insert() frees the state keys. */
if (st) { if (st) {
+6 -12
View File
@@ -4541,10 +4541,8 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, int direction,
return (action); return (action);
} }
} else { } else {
if (sk != NULL) uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, sk); uma_zfree(V_pf_state_key_z, nk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
} }
/* copy back packet headers if we performed NAT operations */ /* 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); free(ri, M_PF_RULE_ITEM);
} }
if (sk != NULL) uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, sk); uma_zfree(V_pf_state_key_z, nk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
return (PF_DROP); 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); return (PF_PASS);
csfailed: csfailed:
if (sk != NULL) uma_zfree(V_pf_state_key_z, sk);
uma_zfree(V_pf_state_key_z, sk); uma_zfree(V_pf_state_key_z, nk);
if (nk != NULL)
uma_zfree(V_pf_state_key_z, nk);
if (sn != NULL) { if (sn != NULL) {
PF_SRC_NODE_LOCK(sn); PF_SRC_NODE_LOCK(sn);
+2 -4
View File
@@ -1576,10 +1576,8 @@ pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd,
void void
pf_normalize_tcp_cleanup(struct pf_kstate *state) pf_normalize_tcp_cleanup(struct pf_kstate *state)
{ {
if (state->src.scrub) uma_zfree(V_pf_state_scrub_z, state->src.scrub);
uma_zfree(V_pf_state_scrub_z, state->src.scrub); uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
if (state->dst.scrub)
uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
/* Someday... flush the TCP segment reassembly descriptors. */ /* Someday... flush the TCP segment reassembly descriptors. */
} }