Fix potential NULL pointer dereferences.