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

zebra: Fix opaque memory leak in rare situation #15216

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

donaldsharp
Copy link
Member

Fix this:
*********************************************************************************** Address Sanitizer Error detected in zebra_opaque.test_zebra_opaque/r3.asan.zebra.11099

================================================================= ==11099==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 66 byte(s) in 1 object(s) allocated from:
#0 0x7f527fc06b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
#1 0x7f527f5e852b in qmalloc lib/memory.c:100
#2 0x56418d20832d in zread_route_add zebra/zapi_msg.c:2125
#3 0x56418d215d08 in zserv_handle_commands zebra/zapi_msg.c:4011
#4 0x56418d32ab5b in zserv_process_messages zebra/zserv.c:520
#5 0x7f527f6938d3 in event_call lib/event.c:2003
#6 0x7f527f5cb692 in frr_run lib/libfrr.c:1218
#7 0x56418d1c3336 in main zebra/main.c:508
#8 0x7f527e656c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 66 byte(s) leaked in 1 allocation(s). ***********************************************************************************

Code inspection leads to some code paths where the opaque data was not freed up.

Fix this:
***********************************************************************************
Address Sanitizer Error detected in zebra_opaque.test_zebra_opaque/r3.asan.zebra.11099

=================================================================
==11099==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 66 byte(s) in 1 object(s) allocated from:
    #0 0x7f527fc06b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
    #1 0x7f527f5e852b in qmalloc lib/memory.c:100
    #2 0x56418d20832d in zread_route_add zebra/zapi_msg.c:2125
    #3 0x56418d215d08 in zserv_handle_commands zebra/zapi_msg.c:4011
    #4 0x56418d32ab5b in zserv_process_messages zebra/zserv.c:520
    #5 0x7f527f6938d3 in event_call lib/event.c:2003
    #6 0x7f527f5cb692 in frr_run lib/libfrr.c:1218
    #7 0x56418d1c3336 in main zebra/main.c:508
    #8 0x7f527e656c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: 66 byte(s) leaked in 1 allocation(s).
***********************************************************************************

Code inspection leads to some code paths where the opaque data was not
freed up.

Signed-off-by: Donald Sharp <[email protected]>
@@ -2693,6 +2693,7 @@ static void early_route_memory_free(struct zebra_early_route *ere)
if (ere->re_nhe)
zebra_nhg_free(ere->re_nhe);

zapi_re_opaque_free(ere->re->opaque);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it'd be good to take several of these common "re" memory free-ers and put them in one common function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a few minutes trying to figure out how to make this better and frankly the whole thing needs to be reworked, which is far more than I want to do at this point in time. This function early_route_memory_free is already abstracted to handle all the freeing points in early_route_add/delete. Let's try to get the address sanitizer problem fixed and I will come back around in the future after I have some time to rework the whole thing

@Jafaral Jafaral added the bugfix label Jan 30, 2024
@Jafaral Jafaral added this to the 10.0 milestone Jan 30, 2024
@github-actions github-actions bot added the rebase PR needs rebase label Jan 30, 2024
@Jafaral Jafaral merged commit 0800546 into FRRouting:master Feb 2, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants