Fixed several memory leaks.