mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 10:37:29 +00:00
bgpd: Fixes for memory leaks.
This commit addresses the memory leaks when certain BGP JSON show commands are executed Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
This commit is contained in:
parent
7611871dfc
commit
74a630b606
@ -46,6 +46,8 @@ void lcommunity_free(struct lcommunity **lcom)
|
|||||||
{
|
{
|
||||||
XFREE(MTYPE_LCOMMUNITY_VAL, (*lcom)->val);
|
XFREE(MTYPE_LCOMMUNITY_VAL, (*lcom)->val);
|
||||||
XFREE(MTYPE_LCOMMUNITY_STR, (*lcom)->str);
|
XFREE(MTYPE_LCOMMUNITY_STR, (*lcom)->str);
|
||||||
|
if ((*lcom)->json)
|
||||||
|
json_object_free((*lcom)->json);
|
||||||
XFREE(MTYPE_LCOMMUNITY, *lcom);
|
XFREE(MTYPE_LCOMMUNITY, *lcom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11594,8 +11594,8 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
|||||||
struct bgp_table *table;
|
struct bgp_table *table;
|
||||||
struct bgp_adj_in *ain;
|
struct bgp_adj_in *ain;
|
||||||
struct bgp_adj_out *adj;
|
struct bgp_adj_out *adj;
|
||||||
unsigned long output_count;
|
unsigned long output_count = 0;
|
||||||
unsigned long filtered_count;
|
unsigned long filtered_count = 0;
|
||||||
struct bgp_node *rn;
|
struct bgp_node *rn;
|
||||||
int header1 = 1;
|
int header1 = 1;
|
||||||
struct bgp *bgp;
|
struct bgp *bgp;
|
||||||
@ -11885,6 +11885,12 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi,
|
|||||||
|
|
||||||
vty_out(vty, "%s\n", json_object_to_json_string_ext(
|
vty_out(vty, "%s\n", json_object_to_json_string_ext(
|
||||||
json, JSON_C_TO_STRING_PRETTY));
|
json, JSON_C_TO_STRING_PRETTY));
|
||||||
|
|
||||||
|
if (!output_count && !filtered_count) {
|
||||||
|
json_object_free(json_scode);
|
||||||
|
json_object_free(json_ocode);
|
||||||
|
}
|
||||||
|
|
||||||
json_object_free(json);
|
json_object_free(json);
|
||||||
} else if (output_count > 0) {
|
} else if (output_count > 0) {
|
||||||
if (filtered_count > 0)
|
if (filtered_count > 0)
|
||||||
|
@ -12192,14 +12192,20 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
|
|||||||
enum show_type type,
|
enum show_type type,
|
||||||
union sockunion *su,
|
union sockunion *su,
|
||||||
const char *conf_if, afi_t afi,
|
const char *conf_if, afi_t afi,
|
||||||
bool use_json, json_object *json)
|
bool use_json)
|
||||||
{
|
{
|
||||||
struct listnode *node, *nnode;
|
struct listnode *node, *nnode;
|
||||||
struct peer *peer;
|
struct peer *peer;
|
||||||
int find = 0;
|
int find = 0;
|
||||||
safi_t safi = SAFI_UNICAST;
|
safi_t safi = SAFI_UNICAST;
|
||||||
|
json_object *json = NULL;
|
||||||
json_object *json_neighbor = NULL;
|
json_object *json_neighbor = NULL;
|
||||||
|
|
||||||
|
if (use_json) {
|
||||||
|
json = json_object_new_object();
|
||||||
|
json_neighbor = json_object_new_object();
|
||||||
|
}
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
|
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
|
||||||
|
|
||||||
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
|
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
|
||||||
@ -12208,16 +12214,15 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
|
|||||||
if ((peer->afc[afi][safi]) == 0)
|
if ((peer->afc[afi][safi]) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (use_json)
|
|
||||||
json_neighbor = json_object_new_object();
|
|
||||||
|
|
||||||
if (type == show_all) {
|
if (type == show_all) {
|
||||||
bgp_show_peer_gr_status(vty, peer, use_json,
|
bgp_show_peer_gr_status(vty, peer, use_json,
|
||||||
json_neighbor);
|
json_neighbor);
|
||||||
|
|
||||||
if (use_json)
|
if (use_json) {
|
||||||
json_object_object_add(json, peer->host,
|
json_object_object_add(json, peer->host,
|
||||||
json_neighbor);
|
json_neighbor);
|
||||||
|
json_neighbor = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (type == show_peer) {
|
} else if (type == show_peer) {
|
||||||
if (conf_if) {
|
if (conf_if) {
|
||||||
@ -12243,8 +12248,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
|
|||||||
json_neighbor);
|
json_neighbor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (find)
|
if (find) {
|
||||||
|
json_neighbor = NULL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == show_peer && !find) {
|
if (type == show_peer && !find) {
|
||||||
@ -12257,6 +12264,10 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,
|
|||||||
vty_out(vty, "%s\n",
|
vty_out(vty, "%s\n",
|
||||||
json_object_to_json_string_ext(
|
json_object_to_json_string_ext(
|
||||||
json, JSON_C_TO_STRING_PRETTY));
|
json, JSON_C_TO_STRING_PRETTY));
|
||||||
|
|
||||||
|
if (json_neighbor)
|
||||||
|
json_object_free(json_neighbor);
|
||||||
|
json_object_free(json);
|
||||||
} else {
|
} else {
|
||||||
vty_out(vty, "\n");
|
vty_out(vty, "\n");
|
||||||
}
|
}
|
||||||
@ -12378,7 +12389,6 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
|
|||||||
int ret;
|
int ret;
|
||||||
struct bgp *bgp;
|
struct bgp *bgp;
|
||||||
union sockunion su;
|
union sockunion su;
|
||||||
json_object *json = NULL;
|
|
||||||
|
|
||||||
bgp = bgp_get_default();
|
bgp = bgp_get_default();
|
||||||
|
|
||||||
@ -12389,20 +12399,17 @@ static void bgp_show_neighbor_graceful_restart_vty(struct vty *vty,
|
|||||||
bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
|
bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
json = json_object_new_object();
|
|
||||||
if (ip_str) {
|
if (ip_str) {
|
||||||
ret = str2sockunion(ip_str, &su);
|
ret = str2sockunion(ip_str, &su);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
|
|
||||||
ip_str, afi,
|
|
||||||
use_json, json);
|
|
||||||
else
|
|
||||||
bgp_show_neighbor_graceful_restart(
|
bgp_show_neighbor_graceful_restart(
|
||||||
vty, bgp, type, &su, NULL, afi, use_json, json);
|
vty, bgp, type, NULL, ip_str, afi, use_json);
|
||||||
|
else
|
||||||
|
bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
|
||||||
|
NULL, afi, use_json);
|
||||||
} else
|
} else
|
||||||
bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
|
bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
|
||||||
afi, use_json, json);
|
afi, use_json);
|
||||||
json_object_free(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
|
static void bgp_show_all_instances_neighbors_vty(struct vty *vty,
|
||||||
|
Loading…
Reference in New Issue
Block a user