From f7c9dc445ca9f4f06587fb8d7199cd00e6f641cb Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 30 Mar 2024 12:06:11 +0100 Subject: [PATCH] Allocate StorageItemRoot directly on list --- source/utils/storage/StorageUtils.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/utils/storage/StorageUtils.cpp b/source/utils/storage/StorageUtils.cpp index f1a2ded..688e07d 100644 --- a/source/utils/storage/StorageUtils.cpp +++ b/source/utils/storage/StorageUtils.cpp @@ -400,7 +400,9 @@ namespace StorageUtils { namespace API { namespace Internal { WUPSStorageError OpenStorage(std::string_view plugin_id, wups_storage_root_item &outItem) { - StorageItemRoot root(plugin_id); + std::lock_guard lock(gStorageMutex); + gStorage.emplace_front(plugin_id); + auto &root = gStorage.front(); WUPSStorageError err = Helper::LoadFromFile(plugin_id, root); if (err == WUPS_STORAGE_ERROR_NOT_FOUND) { @@ -408,14 +410,11 @@ namespace StorageUtils { root = StorageItemRoot(plugin_id); } else if (err != WUPS_STORAGE_ERROR_SUCCESS) { // Return on any other error + gStorage.pop_front(); return err; } outItem = (wups_storage_root_item) root.getHandle(); - { - std::lock_guard lock(gStorageMutex); - gStorage.push_front(std::move(root)); - } return WUPS_STORAGE_ERROR_SUCCESS; }