switch_malloc and switch_zmalloc macros that are fatal if malloc fails both in debug and release modes, switch_zmalloc includes a companion memset for the malloc'd block.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4794 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2007-03-29 17:37:42 +00:00
parent 6e2b76eb75
commit a021945cef
3 changed files with 16 additions and 10 deletions
+10
View File
@@ -247,6 +247,16 @@ SWITCH_DECLARE(switch_status_t) switch_string_match(const char *string, size_t s
#define SWITCH_READ_ACCEPTABLE(status) (status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK)
SWITCH_DECLARE(size_t) switch_url_encode(char *url, char *buf, size_t len);
SWITCH_DECLARE(char *) switch_url_decode(char *s);
/* malloc or DIE macros */
#ifdef NDEBUG
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
#else
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
#endif
SWITCH_END_EXTERN_C
#endif