Since valgrind
is not available on Windows, and its macOS distribution is tricky to install in the latest macOS, we recommend you to run valgrind
in the Linux Lab (Lab 2) by SSH. Here is a procedure to do this using Virtual Barn.
PuTTY
. There is a shortcut on your Desktop. Enter csl2wk13.cse.ust.hk
as the Host Name.
pwd
(Print Working Directory) to verify this. It should show /homes/your_login
FileZilla
from Start Menu. Click "File" -> "Site Manager" -> "New Site". Choose SFTP for protocol. Enter csl2wk13.cse.ust.hk
as Host.
FileZilla
after doing so.
PuTTY
, compile and run your program accordingly.
valgrind
Run your program with valgrind
by:
valgrind --leak-check=full ./pa2_test.exe
# you can change the pa2_test.exe into other executable file path
A report should show up at the end of the output. If you see the following message, your program is free from memory leak:
==12712== HEAP SUMMARY:
==12712== in use at exit: 0 bytes in 0 blocks
==12712== total heap usage: 18 allocs, 18 frees, 720 bytes allocated
==12712==
==12712== All heap blocks were freed -- no leaks are possible
==12712==
==12712== For counts of detected and suppressed errors, rerun with: -v
==12712== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
But if you see the following messages instead, memory leaks could exist in your program:
==62364== LEAK SUMMARY:
==62364== definitely lost: 8 bytes in 2 blocks
==62364== indirectly lost: 0 bytes in 0 blocks
==62364== possibly lost: 0 bytes in 0 blocks
==62364== still reachable: 0 bytes in 0 blocks
==62364== suppressed: 0 bytes in 0 blocks
OR
==13119== LEAK SUMMARY:
==13119== definitely lost: 0 bytes in 0 blocks
==13119== indirectly lost: 0 bytes in 0 blocks
==13119== possibly lost: 0 bytes in 0 blocks
==13119== still reachable: 560 bytes in 14 blocks
==13119== suppressed: 0 bytes in 0 blocks