From 9d1448357e2a8e3c81ff3bf81bd0ec7eb71798c2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 20 Apr 2018 11:46:19 -0400 Subject: [PATCH 1/3] vtysh: Fix leaked memory in error case Signed-off-by: Donald Sharp --- vtysh/vtysh.c | 1 + 1 file changed, 1 insertion(+) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 9fff2ee58c..4974e538ea 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -341,6 +341,7 @@ static int vtysh_execute_func(const char *line, int pager) if (user_mode) { if (strncmp("en", vector_slot(vline, 0), 2) == 0) { + cmd_free_strvec(vline); fprintf(stdout, "%% Command not allowed: enable\n"); return CMD_WARNING; } From 4b85140f5a6eb5b5c2f425940b585a8ace1253e0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 20 Apr 2018 11:48:45 -0400 Subject: [PATCH 2/3] bgpd: remove unnecessary test and allocate a bit earlier The bgp_info_extra_get call gets the extra pointer, which is also needed for the setlabels() call, so move the call to above the setlabels. Also remove an unnecessary test of a pointer since we have already dereferenced it by the time we are testing for it's existence. Signed-off-by: Donald Sharp --- bgpd/bgp_mplsvpn.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 55365df299..bcc448119c 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -565,10 +565,11 @@ leak_update( if (nexthop_self_flag) bgp_info_set_flag(bn, new, BGP_INFO_ANNC_NH_SELF); + bgp_info_extra_get(new); + if (num_labels) setlabels(new, label, num_labels); - bgp_info_extra_get(new); new->extra->parent = bgp_info_lock(parent); if (bgp_orig) @@ -582,7 +583,7 @@ leak_update( struct bgp *bgp_nexthop = bgp; int nh_valid; - if (new->extra && new->extra->bgp_orig) + if (new->extra->bgp_orig) bgp_nexthop = new->extra->bgp_orig; /* From c7ee6c35cb2c7149f6a3ab53cea4d7e212ebe0f6 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 16 May 2018 09:54:03 -0400 Subject: [PATCH 3/3] bgpd: Fix memory leak of ecommunity_ecom2str The creation of a temporary string for the ecommunity was being leaked when debugging is enabled. Write a bit of code to prevent this. Signed-off-by: Donald Sharp --- bgpd/bgp_ecommunity.c | 5 +++++ bgpd/bgp_ecommunity.h | 1 + bgpd/bgp_flowspec.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 85b9ffd8ca..99fe80f055 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -52,6 +52,11 @@ struct ecommunity *ecommunity_new(void) sizeof(struct ecommunity)); } +void ecommunity_strfree(char **s) +{ + XFREE(MTYPE_ECOMMUNITY_STR, *s); +} + /* Allocate ecommunities. */ void ecommunity_free(struct ecommunity **ecom) { diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index 88bdb5e2ae..2f59308d65 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -156,6 +156,7 @@ extern void ecommunity_unintern(struct ecommunity **); extern unsigned int ecommunity_hash_make(void *); extern struct ecommunity *ecommunity_str2com(const char *, int, int); extern char *ecommunity_ecom2str(struct ecommunity *, int, int); +extern void ecommunity_strfree(char **s); extern int ecommunity_match(const struct ecommunity *, const struct ecommunity *); extern char *ecommunity_str(struct ecommunity *); diff --git a/bgpd/bgp_flowspec.c b/bgpd/bgp_flowspec.c index 5db7e37089..6eb1e39884 100644 --- a/bgpd/bgp_flowspec.c +++ b/bgpd/bgp_flowspec.c @@ -166,6 +166,9 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr, BGP_FLOWSPEC_NLRI_STRING_MAX, "EC{%s}", s == NULL ? "none" : s); + + if (s) + ecommunity_strfree(&s); } snprintf(local_string, BGP_FLOWSPEC_NLRI_STRING_MAX, "FS Rx %s %s %s %s", withdraw ?