pf: Free a table entry that cannot be routed

pfr_insert_kentry() returned the error of pfr_route_kentry() and
leaked the entry it had created; pfr_insert_kentries() stopped at the
first entry it could not route and leaked it and the rest of the work
queue, which no caller frees.  Destroy an entry that cannot be routed
and go on with the next.

Reviewed by:		kp
MFC after:		2 weeks
Sponsored by:		Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D60532
This commit is contained in:
R. Christian McDonald committed 2026-10-13 11:53:00 -04:00
1 parent ac64294143
commit 989d72fd3d
1 file changed
+7 -4
+7 -4
View File
@@ -850,15 +850,16 @@ static void
pfr_insert_kentries(struct pfr_ktable *kt,
struct pfr_kentryworkq *workq, time_t tzero)
{
struct pfr_kentry *p;
struct pfr_kentry *p, *q;
int rv, n = 0;
SLIST_FOREACH(p, workq, pfrke_workq) {
SLIST_FOREACH_SAFE(p, workq, pfrke_workq, q) {
rv = pfr_route_kentry(kt, p);
if (rv) {
printf("pfr_insert_kentries: cannot route entry "
"(code=%d).\n", rv);
break;
pfr_destroy_kentry(p);
continue;
}
p->pfrke_counters.pfrkc_tzero = tzero;
n++;
@@ -880,8 +881,10 @@ pfr_insert_kentry(struct pfr_ktable *kt, struct pfr_addr *ad, time_t tzero)
return (ENOMEM);
rv = pfr_route_kentry(kt, p);
if (rv)
if (rv) {
pfr_destroy_kentry(p);
return (rv);
}
p->pfrke_counters.pfrkc_tzero = tzero;
kt->pfrkt_cnt++;