From 14528ab3c6427e77a656bf3e8e5f0e1aa50a9f77 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 19 Nov 2024 11:51:18 +0300 Subject: [PATCH] Added NULL check in `ksmemory_notifyUnhandledFatalSignal` for safety. (#594) --- Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m | 7 ++++++- Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m index e0144a3e..4185baab 100644 --- a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m +++ b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m @@ -570,4 +570,9 @@ bool ksmemory_previous_session_was_terminated_due_to_memory(bool *userPerceptibl bool ksmemory_get_fatal_reports_enabled(void) { return g_FatalReportsEnabled; } -void ksmemory_notifyUnhandledFatalSignal(void) { g_memory->fatal = true; } +void ksmemory_notifyUnhandledFatalSignal(void) +{ + if (g_memory) { + g_memory->fatal = true; + } +} diff --git a/Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m b/Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m index 3beca27d..72506927 100644 --- a/Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m +++ b/Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m @@ -313,4 +313,9 @@ - (void)testNonFatalReportLevel XCTAssertEqual(ksmemory_get_nonfatal_report_level(), KSCrashAppMemoryStateUrgent); } +- (void)testNotifyUnhandledFatalSignal +{ + XCTAssertNoThrow(ksmemory_notifyUnhandledFatalSignal(), @"NULL safety for g_memory"); +} + @end