TagBuilder::RemoveType: added missing tag pool lock before call to tag_pool_put_item

This commit is contained in:
gd 2022-11-08 21:45:55 +02:00 committed by Max Kellermann
parent 115693b046
commit abb28593ce
2 changed files with 8 additions and 0 deletions

2
NEWS
View File

@ -1,4 +1,6 @@
ver 0.23.12 (not yet released) ver 0.23.12 (not yet released)
* tags
- fix crash bug due to race condition
ver 0.23.11 (2022/11/28) ver 0.23.11 (2022/11/28)
* database * database

View File

@ -263,8 +263,14 @@ TagBuilder::RemoveAll() noexcept
void void
TagBuilder::RemoveType(TagType type) noexcept TagBuilder::RemoveType(TagType type) noexcept
{ {
if (items.empty())
/* don't acquire the tag_pool_lock if we're not going
to call tag_pool_put_item() anyway */
return;
const auto begin = items.begin(), end = items.end(); const auto begin = items.begin(), end = items.end();
const std::scoped_lock<Mutex> protect(tag_pool_lock);
items.erase(std::remove_if(begin, end, items.erase(std::remove_if(begin, end,
[type](TagItem *item) { [type](TagItem *item) {
if (item->type != type) if (item->type != type)