Fixed invalid memory free