]> git.puffer.fish Git - matthieu/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)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 18 Nov 2020 17:50:48 +0000 (12:50 -0500)
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 74cbf3a80a9d9b8e0961889db5be94a5fb8b0006..43bfb3e2bc82a25435947a35f05d6724ea05a976 100644 (file)
@@ -903,7 +903,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 612c8ceee77ca1be84ea5a7bdb0ccc19eea9cf61..3bc4c0323371867a2fa3a8be2e5829db4a0faadf 100644 (file)
@@ -1760,19 +1760,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