summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormobash-rasool <mobash.rasool@gmail.com>2023-01-24 09:54:44 +0530
committerGitHub <noreply@github.com>2023-01-24 09:54:44 +0530
commitc6188284fb4be17b7cd9e20e4a44b83e12eb7eed (patch)
tree2aed9afe731692f1bca0c1d027aaea2d29a5c7cf
parentde2e2d5ef09477ff03c17c18eeb1b2cb8da80f84 (diff)
parent88c5852b72a9a437fbfb0b349ab793048175efe1 (diff)
Merge pull request #12677 from opensourcerouting/fix/ospf_potential_memory_leak
ospfd: Free memory for JSON allocated object before return
-rw-r--r--ospfd/ospf_vty.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index f22c1e7e4e..0b0b9d81ee 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -7314,16 +7314,26 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
type = OSPF_OPAQUE_AREA_LSA;
else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
type = OSPF_OPAQUE_AS_LSA;
- else
+ else {
+ if (uj) {
+ if (use_vrf)
+ json_object_free(json_vrf);
+ }
return CMD_WARNING;
+ }
/* `show ip ospf database LSA adv-router ADV_ROUTER'. */
if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
adv_router = ospf->router_id;
else {
ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
- if (!ret)
+ if (!ret) {
+ if (uj) {
+ if (use_vrf)
+ json_object_free(json_vrf);
+ }
return CMD_WARNING;
+ }
}
show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
@@ -7387,9 +7397,12 @@ DEFUN (show_ip_ospf_database_type_adv_router,
} else {
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if ((ospf == NULL) || !ospf->oi_running) {
- vty_out(vty,
- "%% OSPF is not enabled in vrf %s\n",
- vrf_name);
+ if (uj)
+ vty_json(vty, json);
+ else
+ vty_out(vty,
+ "%% OSPF is not enabled in vrf %s\n",
+ vrf_name);
return CMD_SUCCESS;
}
@@ -7400,7 +7413,11 @@ DEFUN (show_ip_ospf_database_type_adv_router,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- vty_out(vty, "%% OSPF is not enabled on vrf default\n");
+ if (uj)
+ vty_json(vty, json);
+ else
+ vty_out(vty,
+ "%% OSPF is not enabled on vrf default\n");
return CMD_SUCCESS;
}
@@ -11274,7 +11291,12 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
if (ospf->new_table == NULL) {
- vty_out(vty, "No OSPF routing information exist\n");
+ if (json) {
+ if (use_vrf)
+ json_object_free(json_vrf);
+ } else {
+ vty_out(vty, "No OSPF routing information exist\n");
+ }
return CMD_SUCCESS;
}