2010-07-21 19:15:18 -04:00
|
|
|
#ifndef UTIL_H_
|
|
|
|
#define UTIL_H_
|
|
|
|
|
2010-07-29 21:11:54 -04:00
|
|
|
#include "queue.h"
|
|
|
|
|
2010-07-21 19:15:18 -04:00
|
|
|
/* Securely free p */
|
|
|
|
#define FREE(p) do { \
|
2010-08-03 15:20:11 -04:00
|
|
|
if (p != NULL) { \
|
|
|
|
free(p); \
|
|
|
|
p = NULL; \
|
|
|
|
} \
|
2010-07-21 19:15:18 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Securely fee single-linked list */
|
2010-07-29 21:11:54 -04:00
|
|
|
#define FREE_SLIST(l, type) do { \
|
2010-08-03 15:20:11 -04:00
|
|
|
type *walk = SLIST_FIRST(l); \
|
|
|
|
while (!SLIST_EMPTY(l)) { \
|
|
|
|
SLIST_REMOVE_HEAD(l, slist); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = SLIST_FIRST(l); \
|
|
|
|
} \
|
2010-07-21 19:15:18 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#endif
|
2010-07-29 21:11:54 -04:00
|
|
|
|
|
|
|
/* Securely fee tail-queues */
|
|
|
|
#define FREE_TAILQ(l, type) do { \
|
2010-08-03 15:20:11 -04:00
|
|
|
type *walk = TAILQ_FIRST(l); \
|
|
|
|
while (!TAILQ_EMPTY(l)) { \
|
|
|
|
TAILQ_REMOVE(l, TAILQ_FIRST(l), tailq); \
|
|
|
|
FREE(walk); \
|
|
|
|
walk = TAILQ_FIRST(l); \
|
|
|
|
} \
|
2010-07-29 21:11:54 -04:00
|
|
|
} while (0)
|