Fixed invalid memory check.