summaryrefslogtreecommitdiff
path: root/lib/memory.h
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-12-02 16:20:00 +0100
committerDavid Lamparter <equinox@diac24.net>2020-04-01 06:53:26 +0200
commit767439c55858d65bf6f5776b7fcd36cc1132565c (patch)
treed6eb0daa9975f6ff20eca5b69955af23a7db97ad /lib/memory.h
parent0bdeb5e58d8fdf8b0f30461a388768112b0e080c (diff)
lib: mark some allocations as "active at exit"
In some cases we really don't want to clean up things even when exiting (i.e. to keep the logging subsystem going.) This adds a flag on MGROUPs to indicate that. [v2: add "(active at exit)" marker text to debug memstats-at-exit] Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/memory.h')
-rw-r--r--lib/memory.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/memory.h b/lib/memory.h
index e4e05faa4f..13f2f9b11a 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -17,6 +17,7 @@
#ifndef _QUAGGA_MEMORY_H
#define _QUAGGA_MEMORY_H
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <frratomic.h>
@@ -48,6 +49,8 @@ struct memgroup {
struct memgroup *next, **ref;
struct memtype *types, **insert;
const char *name;
+ /* ignore group on dumping memleaks at exit */
+ bool active_at_exit;
};
/* macro usage:
@@ -76,7 +79,7 @@ struct memgroup {
*/
#define DECLARE_MGROUP(name) extern struct memgroup _mg_##name;
-#define DEFINE_MGROUP(mname, desc) \
+#define _DEFINE_MGROUP(mname, desc, ...) \
struct memgroup _mg_##mname \
__attribute__((section(".data.mgroups"))) = { \
.name = desc, \
@@ -84,6 +87,7 @@ struct memgroup {
.next = NULL, \
.insert = NULL, \
.ref = NULL, \
+ __VA_ARGS__ \
}; \
static void _mginit_##mname(void) __attribute__((_CONSTRUCTOR(1000))); \
static void _mginit_##mname(void) \
@@ -99,7 +103,13 @@ struct memgroup {
if (_mg_##mname.next) \
_mg_##mname.next->ref = _mg_##mname.ref; \
*_mg_##mname.ref = _mg_##mname.next; \
- }
+ } \
+ /* end */
+
+#define DEFINE_MGROUP(mname, desc) \
+ _DEFINE_MGROUP(mname, desc, )
+#define DEFINE_MGROUP_ACTIVEATEXIT(mname, desc) \
+ _DEFINE_MGROUP(mname, desc, .active_at_exit = true)
#define DECLARE_MTYPE(name) \
extern struct memtype MTYPE_##name[1]; \