Fixed memory errors and leaks exposed by Valgrind.
Merge branch 'master' into vector-props2
Fixed memory errors and leaks exposed by Valgrind.