sudo apt update
sudo apt install valgrind
hello_valgrind.c
#include <stdlib.h>
void f(void)
{
int* x = malloc(10 * sizeof(int));
x[10] = 0; // problem 1: heap block overrun
} // problem 2: memory leak -- x not freed
int main(void)
{
f();
return 0;
}
gcc hello_valgrind.c -o hello_valgrind -O0 -Wall -g -ggdb -fno-inline
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --read-inline-info=yes --log-file="valgrind_log.txt" ./hello_valgrind