]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pbrd: Fix memory leak
authorDonald Sharp <sharpd@nvidia.com>
Fri, 23 Oct 2020 00:53:07 +0000 (20:53 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Fri, 23 Oct 2020 15:28:12 +0000 (11:28 -0400)
On shutdown pbr was leaking the ifp->info ( struct pbr_interface *)
pointer.

Add some code to notice we are being shutdown and cleanup the memory

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
pbrd/pbr_main.c
pbrd/pbr_vrf.c
pbrd/pbr_vrf.h
pbrd/pbr_zebra.c
pbrd/pbr_zebra.h

index 9a9edd79c6712266b4f6c0e26a8fd8ea36f07ea3..01c52f24e53c95cc7e36361f7061c030fd1ba04d 100644 (file)
@@ -82,6 +82,8 @@ static void sigint(void)
 {
        zlog_notice("Terminating on signal");
 
+       pbr_vrf_terminate();
+
        frr_fini();
 
        exit(0);
index 389e5e8be0db189d04ad03ea0aff0355fbd94fe2..3284607406d09d481b192c61239ad82aa1c10936 100644 (file)
@@ -26,6 +26,7 @@
 #include "pbr_map.h"
 #include "pbr_debug.h"
 #include "pbr_nht.h"
+#include "pbr_zebra.h"
 
 DEFINE_MTYPE_STATIC(PBRD, PBR_MAP_VRF, "PBR Map VRF")
 
@@ -137,3 +138,14 @@ void pbr_vrf_init(void)
        vrf_init(pbr_vrf_new, pbr_vrf_enable, pbr_vrf_disable, pbr_vrf_delete,
                 NULL);
 }
+
+void pbr_vrf_terminate(void)
+{
+       struct vrf *vrf;
+       struct interface *ifp;
+
+       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+               FOR_ALL_INTERFACES (vrf, ifp)
+                       pbr_if_del(ifp);
+       }
+}
index c9448762ebf843ec0c4c18f47392ef888190d129..5953387de22d6527c2ae5693f489bc32845ab6a9 100644 (file)
@@ -40,4 +40,5 @@ extern bool pbr_vrf_is_valid(const struct pbr_vrf *pbr_vrf);
 extern bool pbr_vrf_is_enabled(const struct pbr_vrf *pbr_vrf);
 
 extern void pbr_vrf_init(void);
+extern void pbr_vrf_terminate(void);
 #endif
index b8ee974635df67742aed5bae9bc4b7360ee48af6..2a567251b5c5eee6b89a229896db49d4689ddef7 100644 (file)
@@ -59,6 +59,11 @@ struct pbr_interface *pbr_if_new(struct interface *ifp)
        return pbr_ifp;
 }
 
+void pbr_if_del(struct interface *ifp)
+{
+       XFREE(MTYPE_PBR_INTERFACE, ifp->info);
+}
+
 /* Inteface addition message from zebra. */
 int pbr_ifp_create(struct interface *ifp)
 {
index e8f9bff5d9dd96079c358e5d13659a8bfd6fef7d..d0f9ff910ca4fefd604ab187d60b80595bd39b89 100644 (file)
@@ -46,4 +46,7 @@ extern int pbr_ifp_up(struct interface *ifp);
 extern int pbr_ifp_down(struct interface *ifp);
 extern int pbr_ifp_destroy(struct interface *ifp);
 
+/* Free the ifp->info pointer */
+extern void pbr_if_del(struct interface *ifp);
+
 #endif