From c17d1cfebc016ed790df74f0eeb539a4a71fadda Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 25 Aug 2025 06:56:09 -0700 Subject: fixes #2148 Old id_reg_map seems not be freed This simplifies the code to just use a precompiled static list. This should be lighter weight, and provably free from leaks. --- src/core/defs.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/core/defs.h') diff --git a/src/core/defs.h b/src/core/defs.h index 432c0be7..2ad489f6 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -67,7 +67,7 @@ typedef int32_t nni_duration; // Rel. time (ms). typedef void (*nni_cb)(void *); // Some default timing things. -#define NNI_TIME_NEVER ((nni_time) -1) +#define NNI_TIME_NEVER ((nni_time) - 1) #define NNI_TIME_ZERO ((nni_time) 0) #define NNI_SECOND (1000) @@ -239,4 +239,23 @@ typedef nni_type nni_opt_type; #endif // defined(__BYTE_ORDER) #endif // defined() endianness +// nni_alloc allocates memory. In most cases this can just be malloc(). +// However, you may provide a different allocator, for example it is +// possible to use a slab allocator or somesuch. It is permissible for this +// to return NULL if memory cannot be allocated. +extern void *nni_alloc(size_t); + +// nni_zalloc is just like nni_alloc, but ensures that memory is +// initialized to zero. It is a separate function because some platforms +// can use a more efficient zero-based allocation. +extern void *nni_zalloc(size_t); + +// nni_free frees memory allocated with nni_alloc or nni_zalloc. It takes +// a size because some allocators do not track size, or can operate more +// efficiently if the size is provided with the free call. Examples of this +// are slab allocators like this found in Solaris/illumos (see libumem). +// This routine does nothing if supplied with a NULL pointer and zero size. +// Most implementations can just call free() here. +extern void nni_free(void *, size_t); + #endif // CORE_DEFS_H -- cgit v1.2.3-70-g09d2