org-arl / unet-contrib

Unet user contributions
BSD 3-Clause "New" or "Revised" License
11 stars 15 forks source link

Check for memory leakages in UnetSocket C APIs #65

Open notthetup opened 3 years ago

notthetup commented 3 years ago

Originally from https://github.com/org-arl/unet/issues/861

https://valgrind.org/ is great tool for this.

Also look at the macOS tool https://dr-rost.medium.com/detect-memory-leaks-on-macos-4cf257529aa

https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html

Also here's a great guide for how to run valgrind.. https://stackoverflow.com/questions/5134891/how-do-i-use-valgrind-to-find-memory-leaks

notthetup commented 3 years ago

In context of our conversation.. leaks actually works well on the APIs..

❯ leaks --atExit -- ./txdata localhost 1 1101
Connecting to localhost:1101
Transmitting 9 bytes of data to 1
Transmission Complete
Process:         txdata [83534]
Path:            /Users/USER/Documents/*/txdata
Load Address:    0x106643000
Identifier:      txdata
Version:         ???
Code Type:       X86-64
Platform:        macOS
Parent Process:  leaks [83533]

Date/Time:       2021-06-11 20:23:14.347 +0800
Launch Time:     2021-06-11 20:23:13.857 +0800
OS Version:      macOS 11.4 (20F71)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version:  Xcode 12.5 (12E262)

Physical footprint:         496K
Physical footprint (peak):  496K
----

leaks Report Version: 4.0
Process 83534: 212 nodes malloced for 20 KB
Process 83534: 5 leaks for 80 total leaked bytes.

    5 (80 bytes) << TOTAL >>
      1 (16 bytes) ROOT LEAK: 0x7fec1ba04080 [16]  length: 9  "transport"
      1 (16 bytes) ROOT LEAK: 0x7fec1ba04170 [16]  length: 9  "transport"
      1 (16 bytes) ROOT LEAK: 0x7fec1ba04180 [16]  length: 6  "router"
      1 (16 bytes) ROOT LEAK: 0x7fec1ba04190 [16]  length: 6  "uwlink"
      1 (16 bytes) ROOT LEAK: 0x7fec1ba041a0 [16]  length: 3  "phy"