Use valgrind to find out the memory leaks and invalid read/write problems.

It is really helpful in finding the memory corruptions and leaks