Skip to content

Commit

Permalink
zebra: Free Zebra client resources
Browse files Browse the repository at this point in the history
Memory leaks started flowing:

```
AddressSanitizer Topotests Part 0:  15 KB -> 283 KB
AddressSanitizer Topotests Part 1:  1 KB -> 495 KB
AddressSanitizer Topotests Part 2:  13 KB -> 478 KB
AddressSanitizer Topotests Part 3:  39 KB -> 213 KB
AddressSanitizer Topotests Part 4:  30 KB -> 836 KB
AddressSanitizer Topotests Part 5:  0 bytes -> 356 KB
AddressSanitizer Topotests Part 6:  86 KB -> 783 KB
AddressSanitizer Topotests Part 7:  0 bytes -> 354 KB
AddressSanitizer Topotests Part 8:  0 bytes -> 62 KB
AddressSanitizer Topotests Part 9:  408 KB -> 518 KB
```

```
Direct leak of 3584 byte(s) in 1 object(s) allocated from:
    #0 0x7f1957b02d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x559895c55df0 in qcalloc lib/memory.c:105
    #2 0x559895bc1cdf in zserv_client_create zebra/zserv.c:743
    #3 0x559895bc1cdf in zserv_accept zebra/zserv.c:880
    #4 0x559895cf3438 in event_call lib/event.c:1995
    #5 0x559895c3901c in frr_run lib/libfrr.c:1213
    #6 0x559895a698f1 in main zebra/main.c:472
    #7 0x7f195635ec86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
```

Fixes b20acd0 ("bgpd: Use synchronous way to get labels from Zebra")

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
  • Loading branch information
ton31337 committed Jun 27, 2023
1 parent 4262dc3 commit 82d2f87
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion zebra/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ extern void rib_sweep_route(struct event *t);
extern void rib_sweep_table(struct route_table *table);
extern void rib_close_table(struct route_table *table);
extern void rib_init(void);
extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance);
extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance,
uint32_t session_id);
extern unsigned long rib_score_proto_table(uint8_t proto,
unsigned short instance,
struct route_table *table);
Expand Down
9 changes: 8 additions & 1 deletion zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -4627,12 +4627,19 @@ unsigned long rib_score_proto_table(uint8_t proto, unsigned short instance,
}

/* Remove specific by protocol routes. */
unsigned long rib_score_proto(uint8_t proto, unsigned short instance)
unsigned long rib_score_proto(uint8_t proto, unsigned short instance,
uint32_t session_id)
{
struct vrf *vrf;
struct zebra_vrf *zvrf;
struct other_route_table *ort;
unsigned long cnt = 0;
/* If this is a synchronous BGP Zebra client for label/table
* manager, then ignore it. It's not GR-aware, and causes GR to
* be skipped for the session_id == 0 (asynchronous).
*/
if (proto == ZEBRA_ROUTE_BGP && session_id == 1)
return cnt;

RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
zvrf = vrf->info;
Expand Down
10 changes: 2 additions & 8 deletions zebra/zserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,18 +587,12 @@ static void zserv_client_free(struct zserv *client)

close(client->sock);

/* If this is a synchronous BGP Zebra client for label/table
* manager, then ignore it. It's not GR-aware, and causes GR to
* be skipped for the session_id == 0 (asynchronous).
*/
if (client->proto == ZEBRA_ROUTE_BGP && client->session_id == 1)
return;

if (DYNAMIC_CLIENT_GR_DISABLED(client)) {
zebra_mpls_client_cleanup_vrf_label(client->proto);

nroutes = rib_score_proto(client->proto,
client->instance);
client->instance,
client->session_id);
zlog_notice(
"client %d disconnected %lu %s routes removed from the rib",
client->sock, nroutes,
Expand Down

0 comments on commit 82d2f87

Please sign in to comment.