Skip to content

Commit

Permalink
added safeDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
tihmstar committed Dec 11, 2020
1 parent 15e093e commit 2c99513
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions include/libgeneral/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@
# include CUSTOM_LOGGING
#endif

#define safeFree(ptr) ({if (ptr) free(ptr),ptr=NULL;})
#define safeFreeCustom(ptr,func) ({if (ptr) func(ptr),ptr=NULL;})
#define safeFreeConst(ptr) ({if(void *fbuf = (void*)ptr){ptr = NULL; free(fbuf);}})
#define safeFree(ptr) ({if (ptr) {free(ptr); ptr=NULL;}})
#define safeFreeCustom(ptr,func) ({if (ptr) {func(ptr); ptr=NULL;}})
#define safeFreeConst(ptr) ({if(ptr){void *fbuf = (void*)ptr;ptr = NULL; free(fbuf);}})

#ifdef __cplusplus
# define safeDelete(ptr) ({if (ptr) {delete ptr; ptr=NULL;}})
#endif

#ifdef __cplusplus
#include <functional>
Expand Down

0 comments on commit 2c99513

Please sign in to comment.