17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-09 03:58:55 +01:00

fix: the bugs and vulnerabilities SonarCloud reports on PR #216

This commit is contained in:
2026-11-07 22:11:08 +01:00
parent 8e85def98f
commit 7667e5b2ec
65 changed files with 910 additions and 121 deletions

View File

@@ -53,20 +53,29 @@ void add(std::uint64_t const Handle, entry &&Entry)
g_live[Handle] = std::move(Entry);
}
void remove(std::uint64_t const Handle)
// called by the destructors of buffers and images, so it lets no exception out: the registry only serves the report after
// a device loss, and a resource it fails to move to the freed ones mustn't stop the resource from being released
void remove(std::uint64_t const Handle) noexcept
{
std::lock_guard<std::mutex> lock(g_mutex);
auto const lookup{g_live.find(Handle)};
if (lookup == g_live.end())
try
{
return;
std::scoped_lock lock(g_mutex);
auto const lookup{g_live.find(Handle)};
if (lookup == g_live.end())
{
return;
}
lookup->second.freed = std::chrono::steady_clock::now();
g_freed.push_back(std::move(lookup->second));
g_live.erase(lookup);
if (g_freed.size() > freed_kept)
{
g_freed.pop_front();
}
}
lookup->second.freed = std::chrono::steady_clock::now();
g_freed.push_back(std::move(lookup->second));
g_live.erase(lookup);
if (g_freed.size() > freed_kept)
catch (std::exception const &)
{
g_freed.pop_front();
// the entry stays among the live ones, which the report can live with
}
}