Skip to content

Commit

Permalink
ospfd: fix area range memory leak
Browse files Browse the repository at this point in the history
Addressed a memory leak in OSPF by fixing the improper deallocation of
area range nodes when removed from the table. Introducing a new function,
`ospf_range_table_node_destroy` for proper node cleanup, resolved the issue.

The ASan leak log for reference:

```
Direct leak of 56 byte(s) in 2 object(s) allocated from:
    #0 0x7faf661d1d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    sonic-net#1 0x7faf65bce1e9 in qcalloc lib/memory.c:105
    sonic-net#2 0x55a66e0b61cd in ospf_area_range_new ospfd/ospf_abr.c:43
    sonic-net#3 0x55a66e0b61cd in ospf_area_range_set ospfd/ospf_abr.c:195
    sonic-net#4 0x55a66e07f2eb in ospf_area_range ospfd/ospf_vty.c:631
    sonic-net#5 0x7faf65b51548 in cmd_execute_command_real lib/command.c:993
    sonic-net#6 0x7faf65b51f79 in cmd_execute_command_strict lib/command.c:1102
    sonic-net#7 0x7faf65b51fd8 in command_config_read_one_line lib/command.c:1262
    sonic-net#8 0x7faf65b522bf in config_from_file lib/command.c:1315
    sonic-net#9 0x7faf65c832df in vty_read_file lib/vty.c:2605
    sonic-net#10 0x7faf65c83409 in vty_read_config lib/vty.c:2851
    sonic-net#11 0x7faf65bb0341 in frr_config_read_in lib/libfrr.c:977
    sonic-net#12 0x7faf65c6cceb in event_call lib/event.c:1979
    sonic-net#13 0x7faf65bb1488 in frr_run lib/libfrr.c:1213
    sonic-net#14 0x55a66dfb28c4 in main ospfd/ospf_main.c:249
    sonic-net#15 0x7faf651c9c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 56 byte(s) leaked in 2 allocation(s).
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
  • Loading branch information
Keelan10 committed Sep 5, 2023
1 parent ff542b2 commit 35cf10a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,15 @@ static void ospf_finish_final(struct ospf *ospf)
XFREE(MTYPE_OSPF_TOP, ospf);
}

static void ospf_range_table_node_destroy(route_table_delegate_t *delegate,
struct route_table *table, struct route_node *node)
{
XFREE(MTYPE_OSPF_AREA_RANGE, node->info);
XFREE(MTYPE_ROUTE_NODE, node);
}

route_table_delegate_t ospf_range_table_delegate = {.create_node = route_node_create,
.destroy_node = ospf_range_table_node_destroy};

/* allocate new OSPF Area object */
struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id)
Expand Down Expand Up @@ -971,8 +980,8 @@ struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id)
ospf_opaque_type10_lsa_init(new);

new->oiflist = list_new();
new->ranges = route_table_init();
new->nssa_ranges = route_table_init();
new->ranges = route_table_init_with_delegate(&ospf_range_table_delegate);
new->nssa_ranges = route_table_init_with_delegate(&ospf_range_table_delegate);

if (area_id.s_addr == OSPF_AREA_BACKBONE)
ospf->backbone = new;
Expand Down

0 comments on commit 35cf10a

Please sign in to comment.