Skip to content

Commit c60dc2a

Browse files
committed
bgpd: Free memory in set_aspath_replace_access_list
Properly free the dynamically allocated memory held by `str` after its use. The change also maintains the return value of `nb_cli_apply_changes` by using 'ret' variable. The ASan leak log for reference: ``` *********************************************************************************** Address Sanitizer Error detected in bgp_set_aspath_replace.test_bgp_set_aspath_replace/r1.asan.bgpd.11586 ================================================================= ==11586==ERROR: LeakSanitizer: detected memory leaks Direct leak of 92 byte(s) in 3 object(s) allocated from: #0 0x7f4e2951db40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) sonic-net#1 0x7f4e28f19ea2 in qmalloc lib/memory.c:100 sonic-net#2 0x7f4e28edbb08 in frrstr_join lib/frrstr.c:89 sonic-net#3 0x7f4e28e9a601 in argv_concat lib/command.c:183 sonic-net#4 0x56519adf8413 in set_aspath_replace_access_list_magic bgpd/bgp_routemap.c:6174 sonic-net#5 0x56519adf8942 in set_aspath_replace_access_list bgpd/bgp_routemap_clippy.c:683 sonic-net#6 0x7f4e28e9d548 in cmd_execute_command_real lib/command.c:993 sonic-net#7 0x7f4e28e9da0c in cmd_execute_command lib/command.c:1051 sonic-net#8 0x7f4e28e9de8b in cmd_execute lib/command.c:1218 sonic-net#9 0x7f4e28fc4f1c in vty_command lib/vty.c:591 sonic-net#10 0x7f4e28fc53c7 in vty_execute lib/vty.c:1354 sonic-net#11 0x7f4e28fcdc8d in vtysh_read lib/vty.c:2362 sonic-net#12 0x7f4e28fb8c8b in event_call lib/event.c:1979 sonic-net#13 0x7f4e28efd445 in frr_run lib/libfrr.c:1213 sonic-net#14 0x56519ac85d81 in main bgpd/bgp_main.c:510 sonic-net#15 0x7f4e27f40c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) SUMMARY: AddressSanitizer: 92 byte(s) leaked in 3 allocation(s). *********************************************************************************** *********************************************************************************** Address Sanitizer Error detected in bgp_set_aspath_exclude.test_bgp_set_aspath_exclude/r1.asan.bgpd.10385 ================================================================= ==10385==ERROR: LeakSanitizer: detected memory leaks Direct leak of 55 byte(s) in 2 object(s) allocated from: #0 0x7f6814fdab40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40) sonic-net#1 0x7f68149d6ea2 in qmalloc lib/memory.c:100 sonic-net#2 0x7f6814998b08 in frrstr_join lib/frrstr.c:89 sonic-net#3 0x7f6814957601 in argv_concat lib/command.c:183 sonic-net#4 0x5570e05117a1 in set_aspath_exclude_access_list_magic bgpd/bgp_routemap.c:6327 sonic-net#5 0x5570e05119da in set_aspath_exclude_access_list bgpd/bgp_routemap_clippy.c:836 sonic-net#6 0x7f681495a548 in cmd_execute_command_real lib/command.c:993 sonic-net#7 0x7f681495aa0c in cmd_execute_command lib/command.c:1051 sonic-net#8 0x7f681495ae8b in cmd_execute lib/command.c:1218 sonic-net#9 0x7f6814a81f1c in vty_command lib/vty.c:591 sonic-net#10 0x7f6814a823c7 in vty_execute lib/vty.c:1354 sonic-net#11 0x7f6814a8ac8d in vtysh_read lib/vty.c:2362 sonic-net#12 0x7f6814a75c8b in event_call lib/event.c:1979 sonic-net#13 0x7f68149ba445 in frr_run lib/libfrr.c:1213 sonic-net#14 0x5570e03a0d81 in main bgpd/bgp_main.c:510 sonic-net#15 0x7f68139fdc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86) SUMMARY: AddressSanitizer: 55 byte(s) leaked in 2 allocation(s). *********************************************************************************** ``` Signed-off-by: Keelan Cannoo <[email protected]>
1 parent d50812e commit c60dc2a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bgpd/bgp_routemap.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -6163,6 +6163,7 @@ DEFPY_YANG(
61636163
char xpath_value[XPATH_MAXLEN];
61646164
as_t as_configured_value;
61656165
char replace_value[ASN_STRING_MAX_SIZE * 2];
6166+
int ret;
61666167

61676168
if (configured_asn_str &&
61686169
!asn_str2asn(configured_asn_str, &as_configured_value)) {
@@ -6181,7 +6182,9 @@ DEFPY_YANG(
61816182
"%s/rmap-set-action/frr-bgp-route-map:replace-as-path", xpath);
61826183
nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, str);
61836184

6184-
return nb_cli_apply_changes(vty, NULL);
6185+
ret = nb_cli_apply_changes(vty, NULL);
6186+
XFREE(MTYPE_TMP, str);
6187+
return ret;
61856188
}
61866189

61876190
DEFPY_YANG(

0 commit comments

Comments
 (0)