]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Prevent ecommunity_ecom2str memory leak
authorDonald Sharp <sharpd@nvidia.com>
Wed, 18 Nov 2020 17:50:48 +0000 (12:50 -0500)
committerIgor Ryzhov <iryzhov@nfware.com>
Fri, 27 Nov 2020 14:42:42 +0000 (17:42 +0300)
We were allocating but never freeing memory associated with the
ecommunity_ecom2str allocation.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_ecommunity.c
bgpd/bgp_mplsvpn.c

index 3a0400a4b32240400ed04ebce47c745db93f4118..ea99f5f4ecadc0aa2c7f537ca28b11fd3c40d0ba 100644 (file)
@@ -898,7 +898,7 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
        int str_size;
        char *str_buf;
 
-       if (ecom->size == 0)
+       if (!ecom || ecom->size == 0)
                return XCALLOC(MTYPE_ECOMMUNITY_STR, 1);
 
        /* ecom strlen + space + null term */
index 82aa811e988bed461930cb98508268630e3de773..cceedb00e2a2d17ae2e82f7a3d6c1fc4ab0cad71 100644 (file)
@@ -1764,19 +1764,26 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
 
        if (debug) {
                const char *from_name;
+               char *ecom1, *ecom2;
 
                from_name = from_bgp->name ? from_bgp->name :
                        VRF_DEFAULT_NAME;
-               zlog_debug("%s from %s to %s first_export %u import-rt %s export-rt %s",
-                          __func__, from_name, export_name, first_export,
-                          to_bgp->vpn_policy[afi].rtlist[idir] ?
-                          (ecommunity_ecom2str(to_bgp->vpn_policy[afi].
-                                               rtlist[idir],
-                                       ECOMMUNITY_FORMAT_ROUTE_MAP, 0)) : " ",
-                          to_bgp->vpn_policy[afi].rtlist[edir] ?
-                          (ecommunity_ecom2str(to_bgp->vpn_policy[afi].
-                                               rtlist[edir],
-                                       ECOMMUNITY_FORMAT_ROUTE_MAP, 0)) : " ");
+
+               ecom1 = ecommunity_ecom2str(
+                       to_bgp->vpn_policy[afi].rtlist[idir],
+                       ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
+
+               ecom2 = ecommunity_ecom2str(
+                       to_bgp->vpn_policy[afi].rtlist[edir],
+                       ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
+
+               zlog_debug(
+                       "%s from %s to %s first_export %u import-rt %s export-rt %s",
+                       __func__, from_name, export_name, first_export, ecom1,
+                       ecom2);
+
+               ecommunity_strfree(&ecom1);
+               ecommunity_strfree(&ecom2);
        }
 
        /* Does "import_vrf" first need to export its routes or that