]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: fix json object handling
authorMartin Winter <mwinter@opensourcerouting.org>
Fri, 8 Oct 2021 17:19:53 +0000 (19:19 +0200)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Mon, 11 Oct 2021 21:28:09 +0000 (18:28 -0300)
Fix memory leaks when quitting early and double free when headers are
not set.

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
bgpd/bgp_route.c

index 44629b3d7c9edfad909ae36e62bc3e66cbb8c734..f564bbdbc0193bd229e410d130d903e815a74117 100644 (file)
@@ -13676,6 +13676,9 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
                                "No such neighbor or address family");
                        vty_out(vty, "%s\n", json_object_to_json_string(json));
                        json_object_free(json);
+                       json_object_free(json_ar);
+                       json_object_free(json_scode);
+                       json_object_free(json_ocode);
                } else
                        vty_out(vty, "%% No such neighbor or address family\n");
 
@@ -13692,6 +13695,9 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
                                "Inbound soft reconfiguration not enabled");
                        vty_out(vty, "%s\n", json_object_to_json_string(json));
                        json_object_free(json);
+                       json_object_free(json_ar);
+                       json_object_free(json_scode);
+                       json_object_free(json_ocode);
                } else
                        vty_out(vty,
                                "%% Inbound soft reconfiguration not enabled\n");
@@ -13760,14 +13766,17 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,
                        json_object_to_json_string_ext(
                                json, JSON_C_TO_STRING_PRETTY));
 
-               if (!output_count && !filtered_count) {
+               /*
+                * These fields only give up ownership to `json` when `header1`
+                * is used (set to zero). See code in `show_adj_route` and
+                * `show_adj_route_header`.
+                */
+               if (header1 == 1) {
                        json_object_free(json_scode);
                        json_object_free(json_ocode);
                }
 
-               if (json)
-                       json_object_free(json);
-
+               json_object_free(json);
        } else if (output_count > 0) {
                if (filtered_count > 0)
                        vty_out(vty,