From 17f2ab6495ffb956a093c7e246fd6cdc75fc8a78 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 23 Jul 2009 09:00:51 +0000 Subject: [PATCH] add function to simplify free and null operation on pointers git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@9090 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/baconfig.h | 3 +++ bacula/src/lib/mem_pool.h | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index c341826e7c..2d149c02f8 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -612,6 +612,9 @@ int m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...) #define bmalloc(size) b_malloc(__FILE__, __LINE__, (size)) #endif +/* Function to simplify free/reset pointers */ +inline void bfree_and_null(void *&a) { if (a) { free(a); a = NULL; } } + /* * Replace codes needed in both file routines and non-file routines * Job replace codes -- in "replace" diff --git a/bacula/src/lib/mem_pool.h b/bacula/src/lib/mem_pool.h index bd39d75009..b4d2512ba3 100644 --- a/bacula/src/lib/mem_pool.h +++ b/bacula/src/lib/mem_pool.h @@ -58,7 +58,6 @@ extern POOLMEM *sm_check_pool_memory_size(const char *fname, int line, POOLMEM #define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x) extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf); - #else extern POOLMEM *get_pool_memory(int pool); @@ -71,6 +70,16 @@ extern void free_pool_memory(POOLMEM *buf); #endif +/* Function to simplify free/reset pointers */ +inline void bfree_and_null(POOLMEM *&a) { + if (a) { + free_pool_memory(a); + a = NULL; + } +} + +#define free_and_null_pool_memory(a) bfree_and_null((a)) + extern void garbage_collect_memory_pool(); extern void close_memory_pool(); extern void print_memory_pool_stats(); -- 2.39.2