summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2021-09-07 10:10:50 -0400
committerDonald Sharp <sharpd@nvidia.com>2021-09-07 10:10:50 -0400
commit19d37e54a010c38b18f6a3e8b577b6b016ce5a6b (patch)
treed5ae2b79fcaad00e8b5a3a7e21bc7683a7404c75
parent192422ef3b2e0bc533a25ca276f22f36a14265ef (diff)
ospfd: Don't allocate json memory unless we have json output
Several functions in ospf_vty.c were allocating json memory irrelevant if it was needed or not and then at the end of the loop free'ing it if it was not used. Clean up the access pattern. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
-rw-r--r--ospfd/ospf_vty.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 8af4494335..3ae9707f5f 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -10607,9 +10607,10 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
prefix2str(&rn->p, buf1, sizeof(buf1));
- json_route = json_object_new_object();
- if (json)
+ if (json) {
+ json_route = json_object_new_object();
json_object_object_add(json, buf1, json_route);
+ }
switch (or->path_type) {
case OSPF_PATH_INTER_AREA:
@@ -10730,8 +10731,6 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
}
}
}
- if (!json)
- json_object_free(json_route);
}
if (!json)
vty_out(vty, "\n");
@@ -10759,8 +10758,8 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
continue;
int flag = 0;
- json_route = json_object_new_object();
if (json) {
+ json_route = json_object_new_object();
json_object_object_add(
json, inet_ntop(AF_INET, &rn->p.u.prefix4,
buf, sizeof(buf)),
@@ -10875,8 +10874,6 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
}
}
}
- if (!json)
- json_object_free(json_route);
}
if (!json)
vty_out(vty, "\n");
@@ -10905,9 +10902,10 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
char buf1[19];
snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
- json_route = json_object_new_object();
- if (json)
+ if (json) {
+ json_route = json_object_new_object();
json_object_object_add(json, buf1, json_route);
+ }
switch (er->path_type) {
case OSPF_PATH_TYPE1_EXTERNAL:
@@ -11004,8 +11002,6 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
}
}
}
- if (!json)
- json_object_free(json_route);
}
if (!json)
vty_out(vty, "\n");