Testing with Electric Fence
- For leak-ef, it will find the double deallocation, but not the leaks.
- For malloc-use, it does not find leaks
io:~/memtest% ./malloc-test-ef 10
Please enter a command: a 0 10
Please enter a command: q
but it can find double deallocations and reads/writes after end of allocation
and after deallocation
io:~/memtest% ./malloc-test-ef 10
Please enter a command: a 0 10
Please enter a command: r 0 10
Please enter a command: d 0
Please enter a command: d 0
Please enter a command: r 0 1
EF by default checks only for writing beyond the end of allocated space; we can change that through an environment variable:
io:~/memtest% export EF_PROTECT_BELOW=1
io:~/memtest% ./malloc-test-ef 10
Please enter a command: a 0 10
Please enter a command: r 0 -1