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

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

View File

@ -377,8 +377,7 @@ SWITCH_DECLARE(uint32_t) switch_core_scheduler_add_task(time_t task_runtime,
switch_core_scheduler_task_container_t *container, *tp;
switch_mutex_lock(runtime.task_mutex);
assert((container = malloc(sizeof(*container))));
memset(container, 0, sizeof(*container));
switch_zmalloc(container, sizeof(*container));
assert(func);
container->func = func;
time(&container->task.created);

View File

@ -3281,8 +3281,7 @@ SWITCH_DECLARE(uint32_t) switch_ivr_schedule_hangup(time_t runtime, char *uuid,
struct hangup_helper *helper;
size_t len = sizeof(*helper);
assert((helper = malloc(len)));
memset(helper, 0, len);
switch_zmalloc(helper, len);
switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
helper->cause = cause;
@ -3332,8 +3331,7 @@ SWITCH_DECLARE(uint32_t) switch_ivr_schedule_transfer(time_t runtime, char *uuid
len += strlen(context) + 1;
}
assert((helper = malloc(len)));
memset(helper, 0, len);
switch_zmalloc(helper, len);
switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
@ -3380,8 +3378,7 @@ SWITCH_DECLARE(uint32_t) switch_ivr_schedule_broadcast(time_t runtime, char *uui
struct broadcast_helper *helper;
size_t len = sizeof(*helper) + strlen(path) + 1;
assert((helper = malloc(len)));
memset(helper, 0, len);
switch_zmalloc(helper, len);
switch_copy_string(helper->uuid_str, uuid, sizeof(helper->uuid_str));
helper->flags = flags;