Skip to content

Commit

Permalink
Fix error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingosse committed Oct 3, 2024
1 parent 075d517 commit 07e6afd
Showing 1 changed file with 68 additions and 14 deletions.
82 changes: 68 additions & 14 deletions shared/src/Datadog.Trace.ClrProfiler.Native/dynamic_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,28 @@ namespace datadog::shared::nativeloader

HRESULT DynamicDispatcherImpl::LoadClassFactory(REFIID riid)
{
HRESULT GHR = S_OK;
// We consider the loading a success if at least one class factory is properly loaded.
HRESULT GHR = E_FAIL;

if (m_continuousProfilerInstance != nullptr)
{
HRESULT result = m_continuousProfilerInstance->LoadClassFactory(riid);
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load continuous profiler class factory in: ",
m_continuousProfilerInstance->GetFilePath());
m_continuousProfilerInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_continuousProfilerInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand All @@ -210,11 +219,20 @@ namespace datadog::shared::nativeloader
HRESULT result = m_tracerInstance->LoadClassFactory(riid);
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: ", m_tracerInstance->GetFilePath());
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: ",
m_tracerInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_tracerInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand All @@ -223,11 +241,20 @@ namespace datadog::shared::nativeloader
HRESULT result = m_customInstance->LoadClassFactory(riid);
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load custom class factory in: ", m_customInstance->GetFilePath());
Log::Warn("DynamicDispatcherImpl::LoadClassFactory: Error trying to load custom class factory in: ",
m_customInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_customInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand All @@ -236,19 +263,28 @@ namespace datadog::shared::nativeloader

HRESULT DynamicDispatcherImpl::LoadInstance()
{
HRESULT GHR = S_OK;
// We consider the loading a success if at least one class factory is properly loaded.
HRESULT GHR = E_FAIL;

if (m_continuousProfilerInstance != nullptr)
{
HRESULT result = m_continuousProfilerInstance->LoadInstance();
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the continuous profiler instance in: ",
m_continuousProfilerInstance->GetFilePath());
m_continuousProfilerInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_continuousProfilerInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand All @@ -257,11 +293,20 @@ namespace datadog::shared::nativeloader
HRESULT result = m_tracerInstance->LoadInstance();
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the tracer instance in: ", m_tracerInstance->GetFilePath());
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the tracer instance in: ",
m_tracerInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_tracerInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand All @@ -270,11 +315,20 @@ namespace datadog::shared::nativeloader
HRESULT result = m_customInstance->LoadInstance();
if (FAILED(result))
{
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the custom instance in: ", m_customInstance->GetFilePath());
Log::Warn("DynamicDispatcherImpl::LoadInstance: Error trying to load the custom instance in: ",
m_customInstance->GetFilePath(), ", error code: ", result);

// If we cannot load the class factory we release the instance.
m_customInstance.release();
GHR = result;

if (GHR != S_OK)
{
GHR = result;
}
}
else
{
GHR = S_OK;
}
}

Expand Down

0 comments on commit 07e6afd

Please sign in to comment.