Fixed memory free issues.