Fix missing mem freeing on error path.