Fix leaks in error branches.