diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-08-25 06:56:09 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-08-25 10:03:03 -0700 |
| commit | c17d1cfebc016ed790df74f0eeb539a4a71fadda (patch) | |
| tree | 4b5eeee07ae35c1d25adc2bb8575c115b92f05ec /src/core/defs.h | |
| parent | b1ece6af107958d9d3935586778184763a44f5ee (diff) | |
| download | nng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.tar.gz nng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.tar.bz2 nng-c17d1cfebc016ed790df74f0eeb539a4a71fadda.zip | |
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.
Diffstat (limited to 'src/core/defs.h')
| -rw-r--r-- | src/core/defs.h | 23 |
1 files changed, 21 insertions, 2 deletions
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. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitoar.com> // // 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 |
