Fix pointer validity check.