Skip to content

Memory Leak Testing#34

Merged
pilsnerfrajz merged 17 commits into
mainfrom
memory-leaks
Feb 3, 2026
Merged

Memory Leak Testing#34
pilsnerfrajz merged 17 commits into
mainfrom
memory-leaks

Conversation

@pilsnerfrajz
Copy link
Copy Markdown
Owner

Memory Leak Testing

Add memory leak testing with the AddressSanitizer available in clang. Closes #16.

Tests

  • Update Makefile to run tests easily
    • make leaks runs leak tests based on different command line args
    • make test checks the separate functions in disco for leaks
      • Also runs make leaks
    • Add tests/leaks.sh to print sanitizer output in a user-friendly way when running multiple tests:
✅ Leak test with arguments '-h': passed
✅ Leak test with arguments '--help': passed
✅ Leak test with arguments '': passed
tests/leaks.sh: line 5: 34509 Abort trap: 6           $BIN "$@" > /dev/null 2> "$ERR_LOG"
❌ Leak test with arguments 'localhost -P': failed
=================================================================
==34509==ERROR: AddressSanitizer: heap-use-after-free on address 0x604000000a94 at pc 0x000102c00240 bp 0x00016d205f50 sp 0x00016d205f48
READ of size 4 at 0x604000000a94 thread T0
    #0 0x000102c0023c in ping ping.c:286
    #1 0x000102bfce20 in main main.c:315
    #2 0x0001846fdd50  (<unknown module>)

0x604000000a94 is located 4 bytes inside of 48-byte region [0x604000000a90,0x604000000ac0)
freed by thread T0 here:
    #0 0x000103411400 in free+0x7c (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x3d400)
    #1 0x000102c07318 in free_dst_addr_struct utils.c:21
    #2 0x000102c000ac in ping ping.c:258
    #3 0x000102bfce20 in main main.c:315
    #4 0x0001846fdd50  (<unknown module>)

previously allocated by thread T0 here:
    #0 0x00010341130c in malloc+0x78 (libclang_rt.asan_osx_dynamic.dylib:arm64e+0x3d30c)
    #1 0x000102c07690 in get_dst_addr_struct utils.c:70
    #2 0x000102bffd48 in ping ping.c:213
    #3 0x000102bfce20 in main main.c:315
    #4 0x0001846fdd50  (<unknown module>)

SUMMARY: AddressSanitizer: heap-use-after-free ping.c:286 in ping
Shadow bytes around the buggy address:
...
  • Minor formatting fixes

Fix Memory Leaks

The tests revealed multiple leaks which are now fixed:

  • pcap_compile() filters where not freed in src/arp.c or src/syn_scan.c
  • The if_name variable was not freed in src/arp.c
  • Incorrect memory allocation in src/utils.c caused copying of bytes outside of allocated memory
  • if was used instead of else if in src/ping.c which caused a use-after-free of the dst variable

README

Update README

  • Remove outdated info
  • Update ToC
  • Update Testing section
    • Break up integration tests and memory leaks tests into their own sections

@pilsnerfrajz pilsnerfrajz merged commit 2cbb57e into main Feb 3, 2026
5 checks passed
@pilsnerfrajz pilsnerfrajz deleted the memory-leaks branch February 3, 2026 21:55
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.

Test for Memory Leaks

1 participant