Dynamic analysis tools can observe a running process and report memory-related issues that static analysis would miss entirely. In this exercise you will use Valgrind to detect memory leaks in a small C program – and get a first taste of the dynamic instrumentation concept that will be developed further in Task 04 with Intel Pin.
Read the contents of leak.c and compile it:
$ gcc -g -o leak leak.c
The -g flag includes debug symbols so Valgrind can report exact file names and line numbers.
Now run it normally and observe that nothing seems wrong from the outside:
$ ./leak $ echo "exit code: $?"
Run the same binary under Valgrind's memory error detector:
$ valgrind --leak-check=full --show-leak-kinds=all ./leak
Examine the output and answer the following questions:
-g flag and run Valgrind again. What information is now missing from the report, and why?