Nasty free() and malloc() errors. Use valgrind