Fix a crash by checking the proper pointer for validity before deferencing it.