diff options
author | Pat Ruddy <pat@voltanet.io> | 2021-05-26 13:25:46 +0200 |
---|---|---|
committer | Pat Ruddy <pat@voltanet.io> | 2021-06-18 10:34:43 +0200 |
commit | 0e2deb587843fd18682ff20225b8e8930a52ebbc (patch) | |
tree | 046becbcd826e53fc6eddde946e92cb8871f190a | |
parent | Merge pull request #8874 from idryzhov/ospf-routemap-fix (diff) | |
download | frr-0e2deb587843fd18682ff20225b8e8930a52ebbc.tar.xz frr-0e2deb587843fd18682ff20225b8e8930a52ebbc.zip |
lib: add an MTYPE for bitfields
it is handy to be able to see allocated bitfields in the show
memory output.
Signed-off-by: Pat Ruddy <pat@voltanet.io>
-rw-r--r-- | lib/bitfield.h | 6 | ||||
-rw-r--r-- | lib/memory.c | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/bitfield.h b/lib/bitfield.h index 244938933..a3f361ed9 100644 --- a/lib/bitfield.h +++ b/lib/bitfield.h @@ -60,6 +60,8 @@ typedef unsigned int word_t; */ typedef struct {word_t *data; size_t n, m; } bitfield_t; +DECLARE_MTYPE(BITFIELD); + /** * Initialize the bits. * @v: an instance of bitfield_t struct. @@ -70,7 +72,7 @@ typedef struct {word_t *data; size_t n, m; } bitfield_t; do { \ (v).n = 0; \ (v).m = ((N) / WORD_SIZE + 1); \ - (v).data = calloc(1, ((v).m * sizeof(word_t))); \ + (v).data = XCALLOC(MTYPE_BITFIELD, ((v).m * sizeof(word_t))); \ } while (0) /** @@ -193,7 +195,7 @@ static inline unsigned int bf_find_next_set_bit(bitfield_t v, */ #define bf_free(v) \ do { \ - free((v).data); \ + XFREE(MTYPE_BITFIELD, (v).data); \ (v).data = NULL; \ } while (0) diff --git a/lib/memory.c b/lib/memory.c index 0dc8e9052..18811777a 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -36,6 +36,7 @@ struct memgroup **mg_insert = &mg_first; DEFINE_MGROUP(LIB, "libfrr"); DEFINE_MTYPE(LIB, TMP, "Temporary memory"); +DEFINE_MTYPE(LIB, BITFIELD, "Bitfield memory"); static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr) { |