]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
storage: remove unused code
authorVictor Julien <vjulien@oisf.net>
Fri, 24 Nov 2023 18:17:57 +0000 (19:17 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 1 Dec 2023 13:55:37 +0000 (14:55 +0100)
Only used in a unittest; removed that as well.

src/util-storage.c
src/util-storage.h

index 52b819d0e680895de3bdbb35728c7fd76e56a5bd..aec5c1d10fc6f6455992d68d7d7ff93f758a8c67 100644 (file)
@@ -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
index 984bcf8c20bc4c60b6fcfeedfbe0899b360eae14..6942ec2f2b8220d8caede053d86b145206b76dec 100644 (file)
@@ -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