Fix some memory problems.