Valgrind is smart - it is by the author of bzip2 - and an ex-Manchester Uni postgrad.
It emulates your entire program (in an efficient way); but adds code to spot things that go wrong.
Compile the last example, badread: gcc badread.c -g -o badread
From the source we can see two errors; it reads a flag variable without initialising it and allocates memory and forgets about it.
Shows lots of errors about reads from unitialised memory from around the printf and a backtrace to show where it was called from.
Valgrind --leak-check=yes shows the unfreed malloc; and where the malloc was made from.