]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix memory leak for BGP community alias in CLI
authorDonatas Abraitis <donatas@opensourcerouting.org>
Thu, 26 May 2022 11:03:02 +0000 (14:03 +0300)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Mon, 30 May 2022 12:27:53 +0000 (12:27 +0000)
Before:
```
root@spine1-debian-11:~/frr# vtysh -c 'show memory bgpd | include Large Community'
Large Community               :      100     40        4000      100      4000
Large Community value         :      100     12        2400      100      2400
root@spine1-debian-11:~/frr# for x in $(seq 1 100); do vtysh -c 'conf' -c 'bgp community alias 123:123:123 testas' > /dev/null; done
root@spine1-debian-11:~/frr# vtysh -c 'show memory bgpd | include Large Community'
Large Community               :      200     40        8000      200      8000
Large Community value         :      200     12        4800      200      4800
root@spine1-debian-11:~/frr# for x in $(seq 1 100); do vtysh -c 'conf' -c 'bgp community alias 123:123:123 testas' > /dev/null; done
root@spine1-debian-11:~/frr# vtysh -c 'show memory bgpd | include Large Community'
Large Community               :      300     40       12000      300     12000
Large Community value         :      300     12        7200      300      7200
root@spine1-debian-11:~/frr#
```

After:
```
root@spine1-debian-11:~/frr# vtysh -c 'show memory bgpd | include Large Community'
Large Community               :        0     40           0        1        56
Large Community display string:        0   8192           0        1      8200
Large Community value         :        0     12           0        1        24
root@spine1-debian-11:~/frr# for x in $(seq 1 100); do vtysh -c 'conf' -c 'bgp community alias 123:123:123 testas' > /dev/null; done
root@spine1-debian-11:~/frr# vtysh -c 'show memory bgpd | include Large Community'
Large Community               :        0     40           0        1        56
Large Community display string:        0   8192           0        1      8200
Large Community value         :        0     12           0        1        24
root@spine1-debian-11:~/frr#
```

After we call [l]community_str2com(), we should free the memory.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit d13d137a1baaea39a24d857de54200dca39410b2)

bgpd/bgp_vty.c

index 85438a2356fb898bf3d5f35718b66147cfeafa62..a516176670e5401ddd02157eb77846bb9f67a779 100644 (file)
@@ -1608,8 +1608,21 @@ DEFPY(bgp_community_alias, bgp_community_alias_cmd,
        struct community_alias ca2;
        struct community_alias *lookup_community;
        struct community_alias *lookup_alias;
+       struct community *comm;
+       struct lcommunity *lcomm;
+       uint8_t invalid = 0;
 
-       if (!community_str2com(community) && !lcommunity_str2com(community)) {
+       comm = community_str2com(community);
+       if (!comm)
+               invalid++;
+       community_free(&comm);
+
+       lcomm = lcommunity_str2com(community);
+       if (!lcomm)
+               invalid++;
+       lcommunity_free(&lcomm);
+
+       if (invalid > 1) {
                vty_out(vty, "Invalid community format\n");
                return CMD_WARNING;
        }