Skip to content

Commit a609a9c

Browse files
committed
null check for session
1 parent 085e074 commit a609a9c

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

FlashpointSecurePlayer/RegistryStates.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ public async Task StartImportAsync(string templateName, BINARY_TYPE binaryType)
801801
queuedModifications = new Dictionary<ulong, SortedList<DateTime, List<RegistryStateElement>>>();
802802
kcbModificationKeyNames = new Dictionary<ulong, string>();
803803

804+
if (kernelSession != null) {
805+
kernelSession.Dispose();
806+
}
807+
804808
kernelSession = new TraceEventSession(KernelTraceEventParser.KernelSessionName);
805809

806810
try {
@@ -830,6 +834,10 @@ public async Task StartImportAsync(string templateName, BINARY_TYPE binaryType)
830834
kernelSession.Source.Kernel.RegistryKCBRundownEnd += KCBStopped;
831835

832836
Thread processThread = new Thread(delegate () {
837+
if (kernelSession == null) {
838+
return;
839+
}
840+
833841
kernelSession.Source.Process();
834842
});
835843

@@ -897,27 +905,33 @@ private async Task StopImportAsync(bool sync) {
897905
throw new InvalidRegistryStateException("A timeout occured while stopping the Import.");
898906
}
899907

900-
kernelSession.Stop();
901-
kernelSession.Source.Kernel.RegistryQueryValue -= GotValue;
908+
if (kernelSession != null) {
909+
kernelSession.Stop();
910+
kernelSession.Source.Kernel.RegistryQueryValue -= GotValue;
902911

903-
kernelSession.Source.Kernel.RegistryCreate -= ModificationAdded;
904-
kernelSession.Source.Kernel.RegistrySetValue -= ModificationAdded;
905-
kernelSession.Source.Kernel.RegistrySetInformation -= ModificationAdded;
912+
kernelSession.Source.Kernel.RegistryCreate -= ModificationAdded;
913+
kernelSession.Source.Kernel.RegistrySetValue -= ModificationAdded;
914+
kernelSession.Source.Kernel.RegistrySetInformation -= ModificationAdded;
906915

907-
kernelSession.Source.Kernel.RegistryDelete -= ModificationRemoved;
908-
kernelSession.Source.Kernel.RegistryDeleteValue -= ModificationRemoved;
916+
kernelSession.Source.Kernel.RegistryDelete -= ModificationRemoved;
917+
kernelSession.Source.Kernel.RegistryDeleteValue -= ModificationRemoved;
909918

910-
//kernelSession.Source.Kernel.RegistryFlush -= RegistryModified;
911-
912-
kernelSession.Source.Kernel.RegistryKCBCreate -= KCBStarted;
913-
kernelSession.Source.Kernel.RegistryKCBRundownBegin -= KCBStarted;
919+
//kernelSession.Source.Kernel.RegistryFlush -= RegistryModified;
920+
921+
kernelSession.Source.Kernel.RegistryKCBCreate -= KCBStarted;
922+
kernelSession.Source.Kernel.RegistryKCBRundownBegin -= KCBStarted;
923+
924+
kernelSession.Source.Kernel.RegistryKCBDelete -= KCBStopped;
925+
kernelSession.Source.Kernel.RegistryKCBRundownEnd -= KCBStopped;
926+
}
914927

915-
kernelSession.Source.Kernel.RegistryKCBDelete -= KCBStopped;
916-
kernelSession.Source.Kernel.RegistryKCBRundownEnd -= KCBStopped;
917928
SetFlashpointSecurePlayerSection(TemplateName);
918929
} finally {
919-
kernelSession.Dispose();
920-
kernelSession = null;
930+
if (kernelSession != null) {
931+
kernelSession.Dispose();
932+
kernelSession = null;
933+
}
934+
921935
pathNames = null;
922936
ImportStarted = false;
923937
}

0 commit comments

Comments
 (0)