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

T102pdu_build_clib.c: Fix memory leaks #721

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

moshekaplan
Copy link
Contributor

T102pdu_build_clib.c: Fix memory leaks

T102pdu_build_clib.c: Fix memory leaks
@moshekaplan
Copy link
Contributor Author

Before:

~/Desktop/net-snmp/testing$ ASAN_OPTIONS="detect_leaks=1:log_path=$PWD/asan.log:log_exe_name=1: print_cmdline=1"  ./RUNFULLTESTS -g "unit-tests" -r 102
PDU building .. No subtests run 

Test Summary Report
-------------------
PDU building (Wstat: 0 Tests: 0 Failed: 0)
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.15 cusr  0.04 csys =  0.21 CPU)
Result: FAIL

~/Desktop/net-snmp/testing$ cat asan.log.B102pdu_build_clib.273886 

=================================================================
==B102pdu_build_clib==273886==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 280 byte(s) in 1 object(s) allocated from:
    #0 0x7f7b10cde9a7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7f7b0f099787 in snmp_pdu_create /home/user/Desktop/net-snmp/snmplib/snmp_client.c:134
    #2 0x55a11703377d in main /home/user/Desktop/net-snmp/testing/fulltests/unit-tests/T102pdu_build_clib.c:32
    #3 0x7f7b0e623a8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Indirect leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x7f7b10cdefef in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f7b0f1b7b06 in netsnmp_memdup /home/user/Desktop/net-snmp/snmplib/tools.c:285
    #2 0x7f7b0f131bdd in _snmp_build /home/user/Desktop/net-snmp/snmplib/snmp_api.c:3099
    #3 0x7f7b0f1339e0 in snmp_build /home/user/Desktop/net-snmp/snmplib/snmp_api.c:3290
    #4 0x55a11703389d in main /home/user/Desktop/net-snmp/testing/fulltests/unit-tests/T102pdu_build_clib.c:37
    #5 0x7f7b0e623a8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

After:

~/Desktop/net-snmp/testing$ ASAN_OPTIONS="detect_leaks=1:log_path=$PWD/asan.log:log_exe_name=1: print_cmdline=1"  ./RUNFULLTESTS -g "unit-tests" -r 102
PDU building .. ok   
All tests successful.
Files=1, Tests=5,  0 wallclock secs ( 0.01 usr  0.01 sys +  0.06 cusr  0.03 csys =  0.11 CPU)
Result: PASS

@moshekaplan
Copy link
Contributor Author

Note: It may make sense to change the later snmp_pdu_create commands to use SNMP_MSG_SET and SNMP_MSG_INFORM, instead of creating the PDU and then modifying the command field afterward. I only did not because I did not want to change more of the test than minimally needed to make it not trigger LeakSanitizer.

@bvanassche bvanassche merged commit 10d9cff into net-snmp:master Oct 9, 2023
5 checks passed
@bvanassche
Copy link
Contributor

Thanks for the patch!

@moshekaplan moshekaplan deleted the patch-2 branch October 9, 2023 13:38
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

Successfully merging this pull request may close these issues.

None yet

2 participants