Fix some memory bugs.