# HG changeset patch # User Sebastien Jodogne # Date 1779033110 -7200 # Node ID f45d29cd02dfef69106f22a275786137beddc185 # Parent 261a3e91c87097383ecbcbce1c87ef5fa16ec39e added try/catch safeguards diff -r 261a3e91c870 -r f45d29cd02df OrthancFramework/Sources/DataSource/DataSourceReader.cpp --- a/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Sun May 17 17:34:18 2026 +0200 +++ b/OrthancFramework/Sources/DataSource/DataSourceReader.cpp Sun May 17 17:51:50 2026 +0200 @@ -70,48 +70,52 @@ boost::shared_ptr value; std::unique_ptr error; - std::string cacheKey; - bool hasCacheKey = id_->GetCacheKey(cacheKey); + size_t size = 0; - if (cache_ && hasCacheKey) + try { - value = cache_->GetCachedValue(cacheKey); - } + std::string cacheKey; + bool hasCacheKey = id_->GetCacheKey(cacheKey); - if (!value) - { - try + if (cache_ && hasCacheKey) + { + value = cache_->GetCachedValue(cacheKey); + } + + if (!value) { value.reset(source_.Load(*id_)); - } - catch (OrthancException& e) - { - error.reset(new OrthancException(e)); - } - catch (...) - { - error.reset(new OrthancException(ErrorCode_InternalError)); + + if (!error && !value) + { + error.reset(new OrthancException(ErrorCode_NullPointer)); + } + + if (!error && cache_ && hasCacheKey) + { + cache_->Store(cacheKey, value, source_.GetValueSize(*value)); + } } - if (!error && !value) + if (!error) { - error.reset(new OrthancException(ErrorCode_NullPointer)); + size = source_.GetValueSize(*value); } - - if (!error && cache_ && hasCacheKey) - { - cache_->Store(cacheKey, value, source_.GetValueSize(*value)); - } + } + catch (OrthancException& e) + { + error.reset(new OrthancException(e)); + } + catch (...) + { + error.reset(new OrthancException(ErrorCode_InternalError)); } // Phase 2: Acquire budget WITHOUT holding a strong reference to "DataSourceAnswer". // If the "DataSourceAnswer" has been dropped, "answer_.lock()" below will return NULL // and we will immediately "Release()" to revert this. - size_t size = 0; - if (!error) { - size = source_.GetValueSize(*value); budget_->Acquire(size); // may block; "DataSourceAnswer" CAN be destroyed here } diff -r 261a3e91c870 -r f45d29cd02df OrthancFramework/Sources/MultiThreading/ThreadPool.cpp --- a/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Sun May 17 17:34:18 2026 +0200 +++ b/OrthancFramework/Sources/MultiThreading/ThreadPool.cpp Sun May 17 17:51:50 2026 +0200 @@ -233,7 +233,18 @@ if (task.get() != NULL) { - dynamic_cast(*task).Execute(); + try + { + dynamic_cast(*task).Execute(); + } + catch (const OrthancException& e) + { + LOG(ERROR) << "Exception while executing a task: " << e.What(); + } + catch (...) + { + LOG(ERROR) << "Native exception while executing a task"; + } } } } diff -r 261a3e91c870 -r f45d29cd02df OrthancServer/Resources/RunCppCheck-2.20.0.sh --- a/OrthancServer/Resources/RunCppCheck-2.20.0.sh Sun May 17 17:34:18 2026 +0200 +++ b/OrthancServer/Resources/RunCppCheck-2.20.0.sh Sun May 17 17:51:50 2026 +0200 @@ -10,7 +10,7 @@ fi cat < /tmp/cppcheck-suppressions.txt -assertWithSideEffect:../../OrthancFramework/Sources/DataSource/DataSourceReader.cpp:208 +assertWithSideEffect:../../OrthancFramework/Sources/DataSource/DataSourceReader.cpp:212 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:292 assertWithSideEffect:../../OrthancServer/Sources/Database/Compatibility/DatabaseLookup.cpp:391 assertWithSideEffect:../../OrthancServer/Sources/ServerJobs/ResourceModificationJob.cpp:287