summaryrefslogtreecommitdiffstats
path: root/ospfd
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2022-12-19 16:51:58 +0100
committerDonald Sharp <sharpd@nvidia.com>2022-12-20 14:45:51 +0100
commitf9f19fef9d46fe0f1b8d23bc45a5f45ec164ff94 (patch)
tree65a825ef676e4867809404dc34fc25667548d8db /ospfd
parentMerge pull request #12549 from opensourcerouting/fix/bgp_packet_attribute_for... (diff)
downloadfrr-f9f19fef9d46fe0f1b8d23bc45a5f45ec164ff94.tar.xz
frr-f9f19fef9d46fe0f1b8d23bc45a5f45ec164ff94.zip
ospfd: Fix some json mem leaks and some issues
a) if show_function happened to be NULL we would leak json memory b) json_lsa_type was being allocated but only used in the default case, leaking memory c) json output would sometimes produce text output and that is incorrect Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_vty.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 4c1059787..43b7de552 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -6614,14 +6614,17 @@ static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
route_lock_node(start);
for (rn = start; rn; rn = route_next_until(rn, start))
if ((lsa = rn->info)) {
- if (json) {
- json_lsa = json_object_new_object();
- json_object_array_add(json, json_lsa);
- }
+ if (show_function[lsa->data->type] != NULL) {
+ if (json) {
+ json_lsa =
+ json_object_new_object();
+ json_object_array_add(json,
+ json_lsa);
+ }
- if (show_function[lsa->data->type] != NULL)
show_function[lsa->data->type](
vty, lsa, json_lsa);
+ }
}
route_unlock_node(start);
}
@@ -6640,9 +6643,6 @@ static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
json_object *json_areas = NULL;
json_object *json_lsa_array = NULL;
- if (json)
- json_lsa_type = json_object_new_object();
-
switch (type) {
case OSPF_AS_EXTERNAL_LSA:
case OSPF_OPAQUE_AS_LSA:
@@ -6685,6 +6685,7 @@ static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
}
if (json) {
+ json_lsa_type = json_object_new_object();
json_object_object_add(json_lsa_type, "areas",
json_areas);
json_object_object_add(json,
@@ -7158,6 +7159,9 @@ DEFUN (show_ip_ospf_database_max,
vty_out(vty,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);
+ if (uj)
+ json_object_free(json);
+
return CMD_SUCCESS;
}
ret = (show_ip_ospf_database_common(
@@ -7169,6 +7173,9 @@ DEFUN (show_ip_ospf_database_max,
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
vty_out(vty, "%% OSPF is not enabled in vrf default\n");
+ if (uj)
+ json_object_free(json);
+
return CMD_SUCCESS;
}