From db01bb37b2219bc6124de854173769b9802c5c69 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 24 Jan 2023 13:54:28 +0100 Subject: [PATCH] StorageAPI: Improve closeStorage implementation --- libraries/libwups/storage.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libraries/libwups/storage.cpp b/libraries/libwups/storage.cpp index c097008..d8c9b74 100644 --- a/libraries/libwups/storage.cpp +++ b/libraries/libwups/storage.cpp @@ -81,15 +81,14 @@ static void closeItem(wups_storage_item_t *item) { return; } - auto *items = (wups_storage_item_t *) item->data; - - for (uint32_t i = 0; i < item->data_size; i++) { - if (items[i].type == WUPS_STORAGE_TYPE_ITEM) { + if (item->type == WUPS_STORAGE_TYPE_ITEM) { + auto *items = (wups_storage_item_t *) item->data; + for (uint32_t i = 0; i < item->data_size; i++) { closeItem(&items[i]); } - free(items[i].data); - free(items[i].key); } + free(item->data); + free(item->key); } WUPSStorageError WUPS_CloseStorage(void) { @@ -111,7 +110,6 @@ WUPSStorageError WUPS_CloseStorage(void) { isDirty = false; closeItem(&rootItem); - free(rootItem.data); rootItem.data_size = 0; rootItem.data = nullptr; }