]> 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)
committermergify-bot <noreply@mergify.io>
Tue, 26 Oct 2021 15:07:52 +0000 (15:07 +0000)
Fix memory leaks when quitting early and double free when headers are
not set.

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
(cherry picked from commit 690c3134a4f5657bce8d533d8459c2e9e1dcfe86)

bgpd/bgp_route.c

index fc971784500696c5bf97163f58190bc79bed46d9..aafe66aa19c06c5a751d28e5e48607b4747d0d97 100644 (file)
@@ -13677,6 +13677,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");
 
@@ -13693,6 +13696,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");
@@ -13761,14 +13767,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,