From b500346f960eda5fc26fae12c23caf33da44499a Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 16 Mar 2021 13:43:32 +0100 Subject: [PATCH] Enhance bdelete_and_free() macro --- bacula/src/baconfig.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index b7f7c29d3..b3b797d29 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -603,8 +603,18 @@ void t_msg(const char *file, int line, int64_t level, const char *fmt,...); #endif /** Macro to simplify free/reset pointers */ -#define bfree_and_null(a) do{if(a){bfree(a); (a)=NULL;}} while(0) -#define bdelete_and_null(a) do{if(a){delete a; (a)=NULL;}} while(0) +#define bfree_and_null(a) do{if(a){void *b__=(void*)a; (a)=NULL; bfree(b__);}} while(0) + +/* If changed, please run the tests in tools/test-cpp.c */ +#if __cplusplus >= 201103L +# define bdelete_and_null(a) do{if(a){auto b__ = a; (a)=NULL; delete b__;}} while(0) +#else +# ifdef HAVE_TYPEOF +# define bdelete_and_null(a) do{if(a){typeof(a) b__ = a; (a)=NULL; delete b__;}} while(0) +# else +# define bdelete_and_null(a) do{if(a){delete a; (a)=NULL;}} while(0) +# endif +#endif /** * Replace codes needed in both file routines and non-file routines -- 2.47.3