Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional jump or move depends on uninitialised value(s) #23

Closed
qlyoung opened this issue Dec 19, 2016 · 0 comments
Closed

Conditional jump or move depends on uninitialised value(s) #23

qlyoung opened this issue Dec 19, 2016 · 0 comments

Comments

@qlyoung
Copy link
Member

qlyoung commented Dec 19, 2016

Just a small valgrind nit here.

==18558== Conditional jump or move depends on uninitialised value(s)
==18558==    at 0x4E5C1AB: command_match_r (command_match.c:214)
==18558==    by 0x4E5BFB8: command_match (command_match.c:115)
==18558==    by 0x4E5F49A: cmd_execute_command_real (command.c:794)
==18558==    by 0x4E5F7E4: cmd_execute_command_strict (command.c:922)
==18558==    by 0x4E5F835: command_config_read_one_line (command.c:951)
==18558==    by 0x40570B: vtysh_config_from_file (vtysh.c:661)
==18558==    by 0x40A6EA: vtysh_read_file (vtysh_config.c:373)
==18558==    by 0x40A783: vtysh_read_config (vtysh_config.c:398)
==18558==    by 0x403EED: main (vtysh_main.c:371)
==18558==
==18558== Conditional jump or move depends on uninitialised value(s)
==18558==    at 0x4E5C1AB: command_match_r (command_match.c:214)
==18558==    by 0x4E5C357: command_match_r (command_match.c:293)
==18558==    by 0x4E5C357: command_match_r (command_match.c:293)
==18558==    by 0x4E5C357: command_match_r (command_match.c:293)
==18558==    by 0x4E5BFB8: command_match (command_match.c:115)
==18558==    by 0x4E5F49A: cmd_execute_command_real (command.c:794)
==18558==    by 0x4E5F7E4: cmd_execute_command_strict (command.c:922)
==18558==    by 0x4E5F835: command_config_read_one_line (command.c:951)
==18558==    by 0x40570B: vtysh_config_from_file (vtysh.c:661)
==18558==    by 0x40A6EA: vtysh_read_file (vtysh_config.c:373)
==18558==    by 0x40A783: vtysh_read_config (vtysh_config.c:398)
==18558==    by 0x403EED: main (vtysh_main.c:371)
==18558==
cfra referenced this issue in opensourcerouting/frr Nov 29, 2018
ldp-topo1: Use 'label implicit-null' for implicit labels
ranjanyash54 pushed a commit to ranjanyash54/frr that referenced this issue Aug 25, 2021
…etail

cmgd: fix show adapter details cmd help string.
Keelan10 added a commit to Keelan10/frr that referenced this issue Jun 26, 2023
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230372180f in list_new lib/linklist.c:49
    FRRouting#3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
Keelan10 added a commit to Keelan10/frr that referenced this issue Jun 27, 2023
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230372180f in list_new lib/linklist.c:49
    FRRouting#3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
mergify bot pushed a commit that referenced this issue Jun 28, 2023
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230372180f in list_new lib/linklist.c:49
    #3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    #3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x562303721651 in listnode_new lib/linklist.c:71
    #3 0x56230372182b in listnode_add lib/linklist.c:92
    #4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    #5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    #6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #16 0x5623036c6392 in cmd_execute lib/command.c:1221
    #17 0x5623037e75da in vty_command lib/vty.c:591
    #18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #20 0x5623037db4e8 in event_call lib/event.c:1995
    #21 0x562303720f97 in frr_run lib/libfrr.c:1213
    #22 0x56230368615d in main pimd/pim6_main.c:184
    #23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    #3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x562303721651 in listnode_new lib/linklist.c:71
    #3 0x56230372182b in listnode_add lib/linklist.c:92
    #4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    #5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    #6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    #16 0x5623036c6392 in cmd_execute lib/command.c:1221
    #17 0x5623037e75da in vty_command lib/vty.c:591
    #18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #20 0x5623037db4e8 in event_call lib/event.c:1995
    #21 0x562303720f97 in frr_run lib/libfrr.c:1213
    #22 0x56230368615d in main pimd/pim6_main.c:184
    #23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
(cherry picked from commit 24379f0)
mergify bot pushed a commit that referenced this issue Jun 28, 2023
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230372180f in list_new lib/linklist.c:49
    #3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    #3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x562303721651 in listnode_new lib/linklist.c:71
    #3 0x56230372182b in listnode_add lib/linklist.c:92
    #4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    #5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    #6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    #16 0x5623036c6392 in cmd_execute lib/command.c:1221
    #17 0x5623037e75da in vty_command lib/vty.c:591
    #18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #20 0x5623037db4e8 in event_call lib/event.c:1995
    #21 0x562303720f97 in frr_run lib/libfrr.c:1213
    #22 0x56230368615d in main pimd/pim6_main.c:184
    #23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    #3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    #4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    #14 0x5623036c6392 in cmd_execute lib/command.c:1221
    #15 0x5623037e75da in vty_command lib/vty.c:591
    #16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #18 0x5623037db4e8 in event_call lib/event.c:1995
    #19 0x562303720f97 in frr_run lib/libfrr.c:1213
    #20 0x56230368615d in main pimd/pim6_main.c:184
    #21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x56230373dd6b in qcalloc lib/memory.c:105
    #2 0x562303721651 in listnode_new lib/linklist.c:71
    #3 0x56230372182b in listnode_add lib/linklist.c:92
    #4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    #5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    #6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    #7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    #8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    #9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    #10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    #11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    #12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    #13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    #14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    #15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    #16 0x5623036c6392 in cmd_execute lib/command.c:1221
    #17 0x5623037e75da in vty_command lib/vty.c:591
    #18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    #19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    #20 0x5623037db4e8 in event_call lib/event.c:1995
    #21 0x562303720f97 in frr_run lib/libfrr.c:1213
    #22 0x56230368615d in main pimd/pim6_main.c:184
    #23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
(cherry picked from commit 24379f0)

# Conflicts:
#	pimd/pim_iface.c
ryndia added a commit to ryndia/frr that referenced this issue Nov 8, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 10, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 10, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 11, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 13, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 13, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
ryndia added a commit to ryndia/frr that referenced this issue Nov 14, 2023
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    FRRouting#1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
cscarpitta pushed a commit to cscarpitta/frr that referenced this issue Feb 9, 2024
The function aspath_remove_private_asns was using an aspath to perform some operation and didnt free it after usage leading to the leak below.

***********************************************************************************
Address Sanitizer Error detected in bgp_remove_private_as_route_map.test_bgp_remove_private_as_route_map/r2.asan.bgpd.27074

=================================================================
==27074==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#10 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#11 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#12 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#13 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Direct leak of 80 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b44cc in aspath_dup bgpd/bgp_aspath.c:689
    FRRouting#3 0x562b62f48498 in route_set_aspath_prepend bgpd/bgp_routemap.c:2283
    FRRouting#4 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#5 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#6 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#7 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#8 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#9 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#10 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#11 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#12 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#13 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#14 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#15 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#16 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#17 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#18 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#19 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#20 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#21 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#22 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#12 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#13 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#14 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#15 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b313f in aspath_make_str_count bgpd/bgp_aspath.c:551
    FRRouting#3 0x562b630b3ecf in aspath_str_update bgpd/bgp_aspath.c:659
    FRRouting#4 0x562b630b88b7 in aspath_prepend bgpd/bgp_aspath.c:1484
    FRRouting#5 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#6 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#7 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#8 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#9 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#10 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#11 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#12 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#13 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#14 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#15 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#16 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#17 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#18 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#19 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#20 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#21 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#22 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#23 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#24 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#13 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#14 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#15 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#16 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#17 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#18 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#19 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#20 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#21 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#22 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#23 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#24 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#25 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95d28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    #1 0x7fd0a45932ff in qcalloc lib/memory.c:105
    FRRouting#2 0x562b630b280d in assegment_new bgpd/bgp_aspath.c:105
    FRRouting#3 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#4 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#5 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#6 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#7 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#8 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#9 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#10 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#11 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#12 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#13 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#14 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#15 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#16 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f6ae90 in subgroup_coalesce_timer bgpd/bgp_updgrp_adv.c:368
    FRRouting#14 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#15 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#16 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#17 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7fd0a4b95b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7fd0a459301f in qmalloc lib/memory.c:100
    FRRouting#2 0x562b630b2879 in assegment_data_new bgpd/bgp_aspath.c:83
    FRRouting#3 0x562b630b2879 in assegment_new bgpd/bgp_aspath.c:108
    FRRouting#4 0x562b630b28f7 in assegment_dup bgpd/bgp_aspath.c:145
    FRRouting#5 0x562b630b29e8 in assegment_dup_all bgpd/bgp_aspath.c:162
    FRRouting#6 0x562b630b8895 in aspath_prepend bgpd/bgp_aspath.c:1483
    FRRouting#7 0x562b62f484a8 in route_set_aspath_prepend bgpd/bgp_routemap.c:2289
    FRRouting#8 0x7fd0a45ec39a in route_map_apply_ext lib/routemap.c:2690
    FRRouting#9 0x562b62efbb1f in subgroup_announce_check bgpd/bgp_route.c:2434
    FRRouting#10 0x562b62efd4e2 in subgroup_process_announce_selected bgpd/bgp_route.c:2990
    FRRouting#11 0x562b62f6a829 in subgroup_announce_table bgpd/bgp_updgrp_adv.c:765
    FRRouting#12 0x562b62f6acbb in subgroup_announce_route bgpd/bgp_updgrp_adv.c:818
    FRRouting#13 0x562b62f5b844 in updgrp_policy_update_walkcb bgpd/bgp_updgrp.c:1685
    FRRouting#14 0x562b62f59442 in update_group_walkcb bgpd/bgp_updgrp.c:1721
    FRRouting#15 0x7fd0a455a7aa in hash_walk lib/hash.c:270
    FRRouting#16 0x562b62f64a48 in update_group_af_walk bgpd/bgp_updgrp.c:2062
    FRRouting#17 0x562b62f6508c in update_group_walk bgpd/bgp_updgrp.c:2071
    FRRouting#18 0x562b62f6520c in update_group_policy_update bgpd/bgp_updgrp.c:1769
    FRRouting#19 0x562b62f4c2be in bgp_route_map_process_update bgpd/bgp_routemap.c:4501
    FRRouting#20 0x562b62f4d81a in bgp_route_map_process_update_cb bgpd/bgp_routemap.c:4683
    FRRouting#21 0x7fd0a45ed7e8 in route_map_walk_update_list lib/routemap.c:870
    FRRouting#22 0x562b62f337a2 in bgp_route_map_update_timer bgpd/bgp_routemap.c:4695
    FRRouting#23 0x7fd0a463322a in event_call lib/event.c:1970
    FRRouting#24 0x7fd0a4576566 in frr_run lib/libfrr.c:1214
    FRRouting#25 0x562b62dbd8f1 in main bgpd/bgp_main.c:510
    FRRouting#26 0x7fd0a35b8c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 416 byte(s) leaked in 16 allocation(s).
***********************************************************************************

Signed-off-by: ryndia <dindyalsarvesh@gmail.com>
Keelan10 added a commit to Keelan10/frr that referenced this issue Mar 2, 2024
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230372180f in list_new lib/linklist.c:49
    FRRouting#3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
(cherry picked from commit 24379f0)
Keelan10 added a commit to Keelan10/frr that referenced this issue Mar 2, 2024
This commit ensures proper cleanup by deleting the gm_join_list when a PIM interface is deleted. The gm_join_list was previously not being freed, causing a memory leak.

The ASan leak log for reference:
```
***********************************************************************************
Address Sanitizer Error detected in multicast_mld_join_topo1.test_multicast_mld_local_join/r1.asan.pim6d.28070

=================================================================
==28070==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230372180f in list_new lib/linklist.c:49
    FRRouting#3 0x56230361b589 in pim_if_gm_join_add pimd/pim_iface.c:1313
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 192 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 96 byte(s) in 4 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f1b in cmd_execute_command lib/command.c:1053
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x56230361b91d in gm_join_new pimd/pim_iface.c:1288
    FRRouting#3 0x56230361b91d in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#4 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#5 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#6 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#7 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#8 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#9 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#10 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#11 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#12 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#13 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#14 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#15 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#16 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#17 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#18 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#19 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#20 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#21 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7f3605dbfd28 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded28)
    FRRouting#1 0x56230373dd6b in qcalloc lib/memory.c:105
    FRRouting#2 0x562303721651 in listnode_new lib/linklist.c:71
    FRRouting#3 0x56230372182b in listnode_add lib/linklist.c:92
    FRRouting#4 0x56230361ba9a in gm_join_new pimd/pim_iface.c:1295
    FRRouting#5 0x56230361ba9a in pim_if_gm_join_add pimd/pim_iface.c:1326
    FRRouting#6 0x562303642247 in lib_interface_gmp_address_family_static_group_create pimd/pim_nb_config.c:2868
    FRRouting#7 0x562303767280 in nb_callback_create lib/northbound.c:1235
    FRRouting#8 0x562303767280 in nb_callback_configuration lib/northbound.c:1579
    FRRouting#9 0x562303768a1d in nb_transaction_process lib/northbound.c:1710
    FRRouting#10 0x56230376904a in nb_candidate_commit_apply lib/northbound.c:1104
    FRRouting#11 0x5623037692ba in nb_candidate_commit lib/northbound.c:1137
    FRRouting#12 0x562303769dec in nb_cli_classic_commit lib/northbound_cli.c:49
    FRRouting#13 0x56230376fb79 in nb_cli_pending_commit_check lib/northbound_cli.c:88
    FRRouting#14 0x5623036c5bcb in cmd_execute_command_real lib/command.c:991
    FRRouting#15 0x5623036c5f6f in cmd_execute_command lib/command.c:1072
    FRRouting#16 0x5623036c6392 in cmd_execute lib/command.c:1221
    FRRouting#17 0x5623037e75da in vty_command lib/vty.c:591
    FRRouting#18 0x5623037e7a74 in vty_execute lib/vty.c:1354
    FRRouting#19 0x5623037f0253 in vtysh_read lib/vty.c:2362
    FRRouting#20 0x5623037db4e8 in event_call lib/event.c:1995
    FRRouting#21 0x562303720f97 in frr_run lib/libfrr.c:1213
    FRRouting#22 0x56230368615d in main pimd/pim6_main.c:184
    FRRouting#23 0x7f360461bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 400 byte(s) leaked in 11 allocation(s).
***********************************************************************************
```

Signed-off-by: Keelan Cannoo <keelan.cannoo@icloud.com>
(cherry picked from commit 24379f0)
louis-6wind added a commit to louis-6wind/frr that referenced this issue Jun 21, 2024
Fix a crash when doing "show isis database detail json" in
isis_srv6_topo1 topotest.

> #0  raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
> #1  0x00007fad89524e2c in core_handler (signo=6, siginfo=0x7ffe86a4b8b0, context=0x7ffe86a4b780) at lib/sigevent.c:258
> #2  <signal handler called>
> #3  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
> FRRouting#4  0x00007fad8904e537 in __GI_abort () at abort.c:79
> FRRouting#5  0x00007fad8904e40f in __assert_fail_base (fmt=0x7fad891c5688 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7fad8a3e70e8 "json_object_get_type(jso) == json_type_object",
>     file=0x7fad8a3e7064 "./json_object.c", line=590, function=<optimized out>) at assert.c:92
> FRRouting#6  0x00007fad8905d662 in __GI___assert_fail (assertion=0x7fad8a3e70e8 "json_object_get_type(jso) == json_type_object", file=0x7fad8a3e7064 "./json_object.c", line=590,
>     function=0x7fad8a3e7440 "json_object_object_add_ex") at assert.c:101
> FRRouting#7  0x00007fad8a3dfe93 in json_object_object_add_ex () from /lib/x86_64-linux-gnu/libjson-c.so.5
> FRRouting#8  0x000055708e3f8f7f in format_subsubtlv_srv6_sid_structure (sid_struct=0x602000172b70, buf=0x0, json=0x6040000a21d0, indent=6) at isisd/isis_tlvs.c:2880
> FRRouting#9  0x000055708e3f9acb in isis_format_subsubtlvs (subsubtlvs=0x602000172b50, buf=0x0, json=0x6040000a21d0, indent=6) at isisd/isis_tlvs.c:3022
> FRRouting#10 0x000055708e3eefb0 in format_item_ext_subtlvs (exts=0x614000047440, buf=0x0, json=0x6040000a2190, indent=2, mtid=2) at isisd/isis_tlvs.c:1313
> FRRouting#11 0x000055708e3fd599 in format_item_extended_reach (mtid=2, i=0x60300015aed0, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:3763
> FRRouting#12 0x000055708e40d46a in format_item (mtid=2, context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, i=0x60300015aed0, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:6789
> FRRouting#13 0x000055708e40d4fc in format_items_ (mtid=2, context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, items=0x60600021d160, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:6804
> FRRouting#14 0x000055708e40edbc in format_mt_items (context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, m=0x6180000845d8, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:7147
> FRRouting#15 0x000055708e4111e9 in format_tlvs (tlvs=0x618000084480, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:7572
> FRRouting#16 0x000055708e4114ce in isis_format_tlvs (tlvs=0x618000084480, json=0x6040000a1bd0) at isisd/isis_tlvs.c:7613
> FRRouting#17 0x000055708e36f167 in lsp_print_detail (lsp=0x612000058b40, vty=0x0, json=0x6040000a1bd0, dynhost=1 '\001', isis=0x60d00001f800) at isisd/isis_lsp.c:785
> FRRouting#18 0x000055708e36f31f in lsp_print_all (vty=0x0, json=0x6040000a0490, head=0x61f000005488, detail=1 '\001', dynhost=1 '\001', isis=0x60d00001f800) at isisd/isis_lsp.c:820
> FRRouting#19 0x000055708e4379fc in show_isis_database_lspdb_json (json=0x6040000a0450, area=0x61f000005480, level=0, lspdb=0x61f000005488, sysid_str=0x0, ui_level=1) at isisd/isisd.c:2683
> FRRouting#20 0x000055708e437ef9 in show_isis_database_json (json=0x6040000a0310, sysid_str=0x0, ui_level=1, isis=0x60d00001f800) at isisd/isisd.c:2754
> FRRouting#21 0x000055708e438357 in show_isis_database_common (vty=0x62e000060400, json=0x6040000a0310, sysid_str=0x0, ui_level=1, isis=0x60d00001f800) at isisd/isisd.c:2788
> FRRouting#22 0x000055708e438591 in show_isis_database (vty=0x62e000060400, json=0x6040000a0310, sysid_str=0x0, ui_level=1, vrf_name=0x7fad89806300 <vrf_default_name> "default", all_vrf=false)
>     at isisd/isisd.c:2825
> FRRouting#23 0x000055708e43891d in show_database (self=0x55708e5519c0 <show_database_cmd>, vty=0x62e000060400, argc=5, argv=0x6040000a02d0) at isisd/isisd.c:2855
> FRRouting#24 0x00007fad893a9767 in cmd_execute_command_real (vline=0x60300015f220, vty=0x62e000060400, cmd=0x0, up_level=0) at lib/command.c:1002
> FRRouting#25 0x00007fad893a9adc in cmd_execute_command (vline=0x60300015f220, vty=0x62e000060400, cmd=0x0, vtysh=0) at lib/command.c:1061
> FRRouting#26 0x00007fad893aa728 in cmd_execute (vty=0x62e000060400, cmd=0x621000025900 "show isis database detail json ", matched=0x0, vtysh=0) at lib/command.c:1227

Note that prior to 2e670cd, there was also a crash when several SRv6
End SIDs were present.

Fixes: 2e670cd ("isisd: fix display of srv6 subsubtlvs")
Fixes: 648a158 ("isisd: Add SRv6 End.X SID to Sub-TLV format func")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
louis-6wind added a commit to louis-6wind/frr that referenced this issue Jun 21, 2024
Fix a crash when doing "show isis database detail json" in
isis_srv6_topo1 topotest.

> #0  raise (sig=<optimized out>) at ../sysdeps/unix/sysv/linux/raise.c:50
> #1  0x00007fad89524e2c in core_handler (signo=6, siginfo=0x7ffe86a4b8b0, context=0x7ffe86a4b780) at lib/sigevent.c:258
> #2  <signal handler called>
> #3  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
> FRRouting#4  0x00007fad8904e537 in __GI_abort () at abort.c:79
> FRRouting#5  0x00007fad8904e40f in __assert_fail_base (fmt=0x7fad891c5688 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7fad8a3e70e8 "json_object_get_type(jso) == json_type_object",
>     file=0x7fad8a3e7064 "./json_object.c", line=590, function=<optimized out>) at assert.c:92
> FRRouting#6  0x00007fad8905d662 in __GI___assert_fail (assertion=0x7fad8a3e70e8 "json_object_get_type(jso) == json_type_object", file=0x7fad8a3e7064 "./json_object.c", line=590,
>     function=0x7fad8a3e7440 "json_object_object_add_ex") at assert.c:101
> FRRouting#7  0x00007fad8a3dfe93 in json_object_object_add_ex () from /lib/x86_64-linux-gnu/libjson-c.so.5
> FRRouting#8  0x000055708e3f8f7f in format_subsubtlv_srv6_sid_structure (sid_struct=0x602000172b70, buf=0x0, json=0x6040000a21d0, indent=6) at isisd/isis_tlvs.c:2880
> FRRouting#9  0x000055708e3f9acb in isis_format_subsubtlvs (subsubtlvs=0x602000172b50, buf=0x0, json=0x6040000a21d0, indent=6) at isisd/isis_tlvs.c:3022
> FRRouting#10 0x000055708e3eefb0 in format_item_ext_subtlvs (exts=0x614000047440, buf=0x0, json=0x6040000a2190, indent=2, mtid=2) at isisd/isis_tlvs.c:1313
> FRRouting#11 0x000055708e3fd599 in format_item_extended_reach (mtid=2, i=0x60300015aed0, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:3763
> FRRouting#12 0x000055708e40d46a in format_item (mtid=2, context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, i=0x60300015aed0, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:6789
> FRRouting#13 0x000055708e40d4fc in format_items_ (mtid=2, context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, items=0x60600021d160, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:6804
> FRRouting#14 0x000055708e40edbc in format_mt_items (context=ISIS_CONTEXT_LSP, type=ISIS_TLV_MT_REACH, m=0x6180000845d8, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:7147
> FRRouting#15 0x000055708e4111e9 in format_tlvs (tlvs=0x618000084480, buf=0x0, json=0x6040000a1bd0, indent=0) at isisd/isis_tlvs.c:7572
> FRRouting#16 0x000055708e4114ce in isis_format_tlvs (tlvs=0x618000084480, json=0x6040000a1bd0) at isisd/isis_tlvs.c:7613
> FRRouting#17 0x000055708e36f167 in lsp_print_detail (lsp=0x612000058b40, vty=0x0, json=0x6040000a1bd0, dynhost=1 '\001', isis=0x60d00001f800) at isisd/isis_lsp.c:785
> FRRouting#18 0x000055708e36f31f in lsp_print_all (vty=0x0, json=0x6040000a0490, head=0x61f000005488, detail=1 '\001', dynhost=1 '\001', isis=0x60d00001f800) at isisd/isis_lsp.c:820
> FRRouting#19 0x000055708e4379fc in show_isis_database_lspdb_json (json=0x6040000a0450, area=0x61f000005480, level=0, lspdb=0x61f000005488, sysid_str=0x0, ui_level=1) at isisd/isisd.c:2683
> FRRouting#20 0x000055708e437ef9 in show_isis_database_json (json=0x6040000a0310, sysid_str=0x0, ui_level=1, isis=0x60d00001f800) at isisd/isisd.c:2754
> FRRouting#21 0x000055708e438357 in show_isis_database_common (vty=0x62e000060400, json=0x6040000a0310, sysid_str=0x0, ui_level=1, isis=0x60d00001f800) at isisd/isisd.c:2788
> FRRouting#22 0x000055708e438591 in show_isis_database (vty=0x62e000060400, json=0x6040000a0310, sysid_str=0x0, ui_level=1, vrf_name=0x7fad89806300 <vrf_default_name> "default", all_vrf=false)
>     at isisd/isisd.c:2825
> FRRouting#23 0x000055708e43891d in show_database (self=0x55708e5519c0 <show_database_cmd>, vty=0x62e000060400, argc=5, argv=0x6040000a02d0) at isisd/isisd.c:2855
> FRRouting#24 0x00007fad893a9767 in cmd_execute_command_real (vline=0x60300015f220, vty=0x62e000060400, cmd=0x0, up_level=0) at lib/command.c:1002
> FRRouting#25 0x00007fad893a9adc in cmd_execute_command (vline=0x60300015f220, vty=0x62e000060400, cmd=0x0, vtysh=0) at lib/command.c:1061
> FRRouting#26 0x00007fad893aa728 in cmd_execute (vty=0x62e000060400, cmd=0x621000025900 "show isis database detail json ", matched=0x0, vtysh=0) at lib/command.c:1227

Note that prior to 2e670cd, there was no crash but only the last
"srv6-sid-structure" was displayed. A "srv6-sid-structure" should be
displayed for each "sid". This commit also fix this.

Was:

> "srv6-lan-endx-sid": [
>   {
>     "sid": "fc00:0:1:1::",
>     "weight": 0,
>     "algorithm": "SPF",
>     "neighbor-id": "0000.0000.0002"
>   },
>   {
>     "sid": "fc00:0:1:2::",
>     "weight": 0,
>     "algorithm": "SPF",
>     "neighbor-id": "0000.0000.0003"
>   }
> ],
> "srv6-sid-structure": {
>   "loc-block-len": 32,
>   "loc-node-len": 16,
>   "func-len": 16,
>   "arg-len": 0
> },

Now (srv6-sid-structure are identical but they are not always):

> "srv6-lan-endx-sid": [
>   {
>     "sid": "fc00:0:1:1::",
>     "algorithm": "SPF",
>     "neighbor-id": "0000.0000.0002",
>     "srv6-sid-structure": {
>       "loc-block-len": 32,
>       "loc-node-len": 16,
>       "func-len": 8,
>       "arg-len": 0
>     },
>   },
>   {
>     "sid": "fc00:0:1:2::",
>     "algorithm": "SPF",
>     "neighbor-id": "0000.0000.0003",
>     "srv6-sid-structure": {
>       "loc-block-len": 32,
>       "loc-node-len": 16,
>       "func-len": 16,
>       "arg-len": 0
>     },
>   }
> ],

Fixes: 2e670cd ("isisd: fix display of srv6 subsubtlvs")
Fixes: 648a158 ("isisd: Add SRv6 End.X SID to Sub-TLV format func")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant