Fix a few memory bugs.