git: 19bd24caa4c8 - main - fib_dxr: do not leak memory if FIB constellation hits structural limit

From: Marko Zec <zec_at_FreeBSD.org>
Date: Fri, 17 May 2024 16:46:59 UTC
The branch main has been updated by zec:

URL: https://cgit.FreeBSD.org/src/commit/?id=19bd24caa4c8c76ddf138b3a1598a21c8c5c3291

commit 19bd24caa4c8c76ddf138b3a1598a21c8c5c3291
Author:     Marko Zec <zec@FreeBSD.org>
AuthorDate: 2024-05-17 16:36:21 +0000
Commit:     Marko Zec <zec@FreeBSD.org>
CommitDate: 2024-05-17 16:46:41 +0000

    fib_dxr: do not leak memory if FIB constellation hits structural limit
    
    DXR lookup table encoding has an inherent structural limit on the amount
    of binary search ranges it can accomodate.  With the current IPv4 BGP views
    (circa 1 M prefixes) and default DXR encoding we are only at around 5% of
    that limit, so far, far away from hitting it.  Just in case it ever gets
    hit, make sure we free the allocated structures, instead of leaking it.
    
    MFC after:      1 week
---
 sys/netinet/in_fib_dxr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/in_fib_dxr.c b/sys/netinet/in_fib_dxr.c
index 539d7fe6c96f..326710cc4c45 100644
--- a/sys/netinet/in_fib_dxr.c
+++ b/sys/netinet/in_fib_dxr.c
@@ -1320,8 +1320,10 @@ dxr_change_rib_batch(struct rib_head *rnh, struct fib_change_queue *q,
 	dxr_build(new_dxr);
 
 	/* Structural limit exceeded, hard error */
-	if (da->rtbl_top >= BASE_MAX)
+	if (da->rtbl_top >= BASE_MAX) {
+		dxr_destroy(new_dxr);
 		return (FLM_ERROR);
+	}
 
 	if (new_dxr->d == NULL) {
 		dxr_destroy(new_dxr);