git: d99d59a79f29 - main - if_ovpn: fix memory leak on unload

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Wed, 21 Sep 2022 19:45:19 UTC
The branch main has been updated by kp:

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

commit d99d59a79f29613593e3a817d59b321550114a25
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2022-09-21 15:23:51 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2022-09-21 19:44:59 +0000

    if_ovpn: fix memory leak on unload
    
    When we're unloading the if_ovpn module we sometimes end up only freeing
    the softc after the module is unloaded and the M_OVPN malloc type no
    longer exists.
    
    Don't return from ovpn_clone_destroy() until the epoch callbacks have
    been called, which ensures that we've freed the softc before we destroy
    M_OVPN.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/net/if_ovpn.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c
index e2b8322d6df5..82e6dd4f6eee 100644
--- a/sys/net/if_ovpn.c
+++ b/sys/net/if_ovpn.c
@@ -2421,6 +2421,8 @@ ovpn_clone_destroy(struct if_clone *ifc, struct ifnet *ifp)
 	if (unit != IF_DUNIT_NONE)
 		ifc_free_unit(ifc, unit);
 
+	NET_EPOCH_DRAIN_CALLBACKS();
+
 	return (0);
 }