From: Eric Bollengier Date: Thu, 23 Jul 2009 09:00:51 +0000 (+0000) Subject: add function to simplify free and null operation on pointers X-Git-Tag: Release-5.0.0~472 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=07a4c859c2d59d57f4e32381873e47fe94cf16ae;p=bacula%2Fbacula 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 --- 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();