]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: fix area range memory leak
authorKeelan10 <keelan.cannoo@icloud.com>
Tue, 22 Aug 2023 21:00:46 +0000 (01:00 +0400)
committerKeelan10 <keelan.cannoo@icloud.com>
Tue, 5 Sep 2023 08:54:33 +0000 (12:54 +0400)
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)
    #1 0x7faf65bce1e9 in qcalloc lib/memory.c:105
    #2 0x55a66e0b61cd in ospf_area_range_new ospfd/ospf_abr.c:43
    #3 0x55a66e0b61cd in ospf_area_range_set ospfd/ospf_abr.c:195
    #4 0x55a66e07f2eb in ospf_area_range ospfd/ospf_vty.c:631
    #5 0x7faf65b51548 in cmd_execute_command_real lib/command.c:993
    #6 0x7faf65b51f79 in cmd_execute_command_strict lib/command.c:1102
    #7 0x7faf65b51fd8 in command_config_read_one_line lib/command.c:1262
    #8 0x7faf65b522bf in config_from_file lib/command.c:1315
    #9 0x7faf65c832df in vty_read_file lib/vty.c:2605
    #10 0x7faf65c83409 in vty_read_config lib/vty.c:2851
    #11 0x7faf65bb0341 in frr_config_read_in lib/libfrr.c:977
    #12 0x7faf65c6cceb in event_call lib/event.c:1979
    #13 0x7faf65bb1488 in frr_run lib/libfrr.c:1213
    #14 0x55a66dfb28c4 in main ospfd/ospf_main.c:249
    #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>
ospfd/ospfd.c

index aa3cadf99788b218f3dd9a3edaae7713aadcac83..e3ed4f2f346d33fb996074727b448d32ca587e62 100644 (file)
@@ -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)
@@ -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;