valgrind for memcheck

Using now valgrind for the memory check (testruns/basicMemtest.sh).
Some minor changes and bugfixes for it.