diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
index 6dcd7da5e6..749dd96548 100644
--- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
+++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c
@@ -236,7 +236,7 @@ ProtectUefiImage (
     //
     // CPU ARCH present. Update memory attribute directly.
     //
-    if (PcdGetBool (PcdEnableUserSpace) && (PdbPointer != NULL)) {
+    if (PcdGetBool (PcdEnableUserSpace) && (!RETURN_ERROR (PdbStatus))) {
       if (AsciiStrStr (PdbPointer, "Fat") != NULL) {
         SetUefiImageProtectionAttributes (ImageRecord, TRUE);
         *IsUserImage = TRUE;