Fix crashes caused by invalid pointer access.