diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
index ae202c3fe24a..19577ff18242 100644
--- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
+++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
@@ -1,7 +1,7 @@
/** @file
Miscellaneous routines for iSCSI driver.
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -624,9 +624,10 @@ IScsiCleanDriverData (
}
EXIT:
-
- gBS->CloseEvent (Private->ExitBootServiceEvent);
-
+ if (Private->ExitBootServiceEvent != NULL) {
+ gBS->CloseEvent (Private->ExitBootServiceEvent);
+ }
+
FreePool (Private);
return Status;
}
@@ -872,7 +873,9 @@ IScsiOnExitBootService (
ISCSI_DRIVER_DATA *Private;
Private = (ISCSI_DRIVER_DATA *) Context;
+
gBS->CloseEvent (Private->ExitBootServiceEvent);
+ Private->ExitBootServiceEvent = NULL;
IScsiSessionAbort (&Private->Session);
}