diff --git a/runtime/context/context.inl b/runtime/context/context.inl index 362d94a8e4..094c5fb61e 100644 --- a/runtime/context/context.inl +++ b/runtime/context/context.inl @@ -26,6 +26,7 @@ namespace OCLRT { template void Context::registerSharing(Sharing *sharing) { + UNRECOVERABLE_IF(!sharing); this->sharingFunctions[Sharing::sharingId].reset(sharing); } diff --git a/unit_tests/context/context_tests.cpp b/unit_tests/context/context_tests.cpp index d2bf99ab58..5390e3d7f9 100644 --- a/unit_tests/context/context_tests.cpp +++ b/unit_tests/context/context_tests.cpp @@ -299,6 +299,12 @@ TEST_F(ContextTest, givenContextWhenSharingTableEmptyThenReturnsNullptr) { EXPECT_EQ(sharingF, nullptr); } +TEST_F(ContextTest, givenNullptrWhenRegisteringSharingToContextThenAbortExecution) { + MockContext context; + context.clearSharingFunctions(); + EXPECT_THROW(context.registerSharing(nullptr), std::exception); +} + TEST_F(ContextTest, givenContextWhenSharingTableIsNotEmptyThenReturnsSharingFunctionPointer) { MockContext context; MockSharingFunctions *sharingFunctions = new MockSharingFunctions;