From: Victor Julien Date: Fri, 24 Nov 2023 18:17:57 +0000 (+0100) Subject: storage: remove unused code X-Git-Tag: suricata-8.0.0-beta1~2029 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69f61c00281d28009270275cc8f53ac10e2fb513;p=thirdparty%2Fsuricata.git storage: remove unused code Only used in a unittest; removed that as well. --- diff --git a/src/util-storage.c b/src/util-storage.c index 52b819d0e6..aec5c1d10f 100644 --- a/src/util-storage.c +++ b/src/util-storage.c @@ -251,36 +251,6 @@ void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id) return storage[id]; } -void *StorageAllocById(Storage **storage, StorageEnum type, int id) -{ -#ifdef DEBUG - BUG_ON(!storage_registration_closed); -#endif - SCLogDebug("storage %p id %d", storage, id); - - StorageMapping *map = &storage_map[type][id]; - Storage *store = *storage; - if (store == NULL) { - // coverity[suspicious_sizeof : FALSE] - store = SCCalloc(storage_max_id[type], sizeof(void *)); - if (unlikely(store == NULL)) - return NULL; - } - SCLogDebug("store %p", store); - - if (store[id] == NULL && map->Alloc != NULL) { - store[id] = map->Alloc(map->size); - if (store[id] == NULL) { - SCFree(store); - *storage = NULL; - return NULL; - } - } - - *storage = store; - return store[id]; -} - void StorageFreeById(Storage *storage, StorageEnum type, int id) { #ifdef DEBUG @@ -326,32 +296,6 @@ void StorageFreeAll(Storage *storage, StorageEnum type) } } -void StorageFree(Storage **storage, StorageEnum type) -{ - if (*storage == NULL) - return; - -#ifdef DEBUG - BUG_ON(!storage_registration_closed); -#endif -#ifdef UNITTESTS - if (storage_map == NULL) - return; -#endif - - Storage *store = *storage; - int i; - for (i = 0; i < storage_max_id[type]; i++) { - if (store[i] != NULL) { - StorageMapping *map = &storage_map[type][i]; - map->Free(store[i]); - store[i] = NULL; - } - } - SCFree(*storage); - *storage = NULL; -} - #ifdef UNITTESTS static void *StorageTestAlloc(unsigned int size) @@ -389,87 +333,6 @@ error: return 0; } -struct StorageTest02Data { - int abc; -}; - -static void *StorageTest02Init(unsigned int size) -{ - struct StorageTest02Data *data = (struct StorageTest02Data *)SCMalloc(size); - if (data != NULL) - data->abc = 1234; - return (void *)data; -} - -static int StorageTest02(void) -{ - struct StorageTest02Data *test = NULL; - - StorageInit(); - - int id1 = StorageRegister(STORAGE_HOST, "test", 4, StorageTest02Init, StorageTestFree); - if (id1 < 0) { - printf("StorageRegister failed (2): "); - goto error; - } - int id2 = StorageRegister(STORAGE_HOST, "test2", 4, StorageTest02Init, StorageTestFree); - if (id2 < 0) { - printf("StorageRegister failed (2): "); - goto error; - } - - if (StorageFinalize() < 0) { - printf("StorageFinalize failed: "); - goto error; - } - - Storage *storage = NULL; - void *data = StorageAllocById(&storage, STORAGE_HOST, id1); - if (data == NULL) { - printf("StorageAllocById failed, data == NULL, storage %p: ", storage); - goto error; - } - test = (struct StorageTest02Data *)data; - if (test->abc != 1234) { - printf("setup failed, test->abc != 1234, but %d (1):", test->abc); - goto error; - } - test->abc = 4321; - - data = StorageAllocById(&storage, STORAGE_HOST, id2); - if (data == NULL) { - printf("StorageAllocById failed, data == NULL, storage %p: ", storage); - goto error; - } - test = (struct StorageTest02Data *)data; - if (test->abc != 1234) { - printf("setup failed, test->abc != 1234, but %d (2):", test->abc); - goto error; - } - - data = StorageGetById(storage, STORAGE_HOST, id1); - if (data == NULL) { - printf("StorageAllocById failed, data == NULL, storage %p: ", storage); - goto error; - } - test = (struct StorageTest02Data *)data; - if (test->abc != 4321) { - printf("setup failed, test->abc != 4321, but %d (3):", test->abc); - goto error; - } - - //StorageFreeById(storage, STORAGE_HOST, id1); - //StorageFreeById(storage, STORAGE_HOST, id2); - - StorageFree(&storage, STORAGE_HOST); - - StorageCleanup(); - return 1; -error: - StorageCleanup(); - return 0; -} - static int StorageTest03(void) { StorageInit(); @@ -541,7 +404,6 @@ error: void StorageRegisterTests(void) { UtRegisterTest("StorageTest01", StorageTest01); - UtRegisterTest("StorageTest02", StorageTest02); UtRegisterTest("StorageTest03", StorageTest03); } #endif diff --git a/src/util-storage.h b/src/util-storage.h index 984bcf8c20..6942ec2f2b 100644 --- a/src/util-storage.h +++ b/src/util-storage.h @@ -66,11 +66,8 @@ int StorageSetById(Storage *storage, const StorageEnum type, const int id, void /** \brief AllocById func for prealloc'd base storage (storage ptrs are part * of another memory block) */ void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id); -/** \brief AllocById func for when we manage the Storage ptr itself */ -void *StorageAllocById(Storage **storage, const StorageEnum type, const int id); void StorageFreeById(Storage *storage, const StorageEnum type, const int id); void StorageFreeAll(Storage *storage, const StorageEnum type); -void StorageFree(Storage **storage, const StorageEnum type); void StorageRegisterTests(void); #endif