From d136b3c1b70d7ae687b763c59d1bc03d4ad3dbc2 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 16 Jun 2024 13:17:35 +0530 Subject: c: improve memory management --- include/util.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include') diff --git a/include/util.h b/include/util.h index c5aa0ab..5279a07 100644 --- a/include/util.h +++ b/include/util.h @@ -5,5 +5,19 @@ #define print_err(fmt, ...) \ fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) +#define LIST_FOREACH_FREE(cur, next, head, field, func_free) \ + for ((cur) = ((head)->lh_first); (cur);) { \ + (next) = ((cur)->field.le_next); \ + func_free((cur)); \ + (cur) = (next); \ + } + +#define CIRCLEQ_FOREACH_FREE(cur, next, head, field, func_free) \ + for ((cur) = ((head)->cqh_first); (cur) != (const void *)(head);) { \ + (next) = ((cur)->field.cqe_next); \ + func_free((cur)); \ + (cur) = (next); \ + } + int json_streaming_read(FILE *stream, cJSON **json); int vpopen(FILE **stream, const char *file, char *const argv[]); -- cgit v1.2.3