Check if pDoc is null before using it

Change-Id: I8eede8774eebdf32c2749325777bcb5a9b1a720b