diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-21 21:27:07 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-30 23:40:45 +0000 |
commit | 620de98d0ce8d6a9207a6a54c7fc66cfa55f7797 (patch) | |
tree | fbfef069e358d20cbbfe53258fe172bab4bed9d5 /src/libutil/pool.hh | |
parent | 4b730f328e1ea581d09ffba4b064b5f3949af414 (diff) |
libutil: drop Pool resources on exceptional free
if a scope owning a resource does not gracefully drop that resource
while handling exceptions from deeper down the call stack we should
assume the resource is invalid state and drop it. currently it *is*
true that such cases do not cause resources to be freed, but thanks
to validator misuses this has so far not caused any larger problem.
Change-Id: Ie4f91bcd60a64d05c5ff9d22cc97954816d13b97
Diffstat (limited to 'src/libutil/pool.hh')
-rw-r--r-- | src/libutil/pool.hh | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libutil/pool.hh b/src/libutil/pool.hh index 6247b6125..548e7ce69 100644 --- a/src/libutil/pool.hh +++ b/src/libutil/pool.hh @@ -1,6 +1,7 @@ #pragma once ///@file +#include <exception> #include <functional> #include <limits> #include <list> @@ -118,7 +119,7 @@ public: if (!r) return; { auto state_(pool.state.lock()); - if (!bad) + if (!bad && !std::uncaught_exceptions()) state_->idle.push_back(ref<R>(r)); assert(state_->inUse); state_->inUse--; @@ -134,6 +135,12 @@ public: Handle get() { + // we do not want to handle the complexity that comes with allocating + // resources during stack unwinding. it would be possible to do this, + // but doing so requires more per-handle bookkeeping to properly free + // resources allocated during unwinding. that effort is not worth it. + assert(std::uncaught_exceptions() == 0); + { auto state_(state.lock()); |