From a2b4369cc29002a80d98ada285e4f1e782089914 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sun, 15 Nov 2009 02:14:50 +0000 Subject: [PATCH] replace all malloc calls to zap_malloc git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@862 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/freetdm/src/fsk.c | 8 ++++---- libs/freetdm/src/hashtable.c | 9 +++++---- libs/freetdm/src/include/openzap.h | 6 +++--- libs/freetdm/src/isdn/Q921.c | 3 ++- libs/freetdm/src/libteletone_generate.c | 3 ++- libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c | 2 +- libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c | 2 +- libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c | 4 ++-- libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c | 2 +- libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c | 6 +++--- libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c | 9 ++++----- libs/freetdm/src/uart.c | 3 ++- libs/freetdm/src/zap_buffer.c | 4 ++-- libs/freetdm/src/zap_io.c | 8 +++----- libs/freetdm/src/zap_m3ua.c | 2 +- libs/freetdm/src/zap_threadmutex.c | 6 +++--- 16 files changed, 39 insertions(+), 38 deletions(-) diff --git a/libs/freetdm/src/fsk.c b/libs/freetdm/src/fsk.c index 773b0deaae..f55d421559 100644 --- a/libs/freetdm/src/fsk.c +++ b/libs/freetdm/src/fsk.c @@ -32,7 +32,7 @@ * * 2005 03 20 R. Krten created */ - +#include #include #include #include @@ -134,7 +134,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) double phi_mark, phi_space; dsp_fsk_handle_t *handle; - handle = malloc(sizeof(*handle)); + handle = zap_malloc(sizeof(*handle)); if (!handle) { return NULL; } @@ -157,7 +157,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) /* allocate the correlation sin/cos arrays and initialize */ for (i = 0; i < 4; i++) { - handle->correlates[i] = malloc(sizeof(double) * handle->corrsize); + handle->correlates[i] = zap_malloc(sizeof(double) * handle->corrsize); if (handle->correlates[i] == NULL) { /* some failed, back out memory allocations */ dsp_fsk_destroy(&handle); @@ -177,7 +177,7 @@ dsp_fsk_handle_t *dsp_fsk_create(dsp_fsk_attr_t *attr) } /* initialize the ring buffer */ - handle->buffer = malloc(sizeof(double) * handle->corrsize); + handle->buffer = zap_malloc(sizeof(double) * handle->corrsize); if (!handle->buffer) { /* failed; back out memory allocations */ dsp_fsk_destroy(&handle); return NULL; diff --git a/libs/freetdm/src/hashtable.c b/libs/freetdm/src/hashtable.c index eeb2aaa07a..415dda7d8d 100644 --- a/libs/freetdm/src/hashtable.c +++ b/libs/freetdm/src/hashtable.c @@ -31,6 +31,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "openzap.h" #include "hashtable.h" #include "hashtable_private.h" #include @@ -69,9 +70,9 @@ create_hashtable(unsigned int minsize, for (pindex=0; pindex < prime_table_length; pindex++) { if (primes[pindex] > minsize) { size = primes[pindex]; break; } } - h = (struct hashtable *)malloc(sizeof(struct hashtable)); + h = (struct hashtable *)zap_malloc(sizeof(struct hashtable)); if (NULL == h) return NULL; /*oom*/ - h->table = (struct entry **)malloc(sizeof(struct entry*) * size); + h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size); if (NULL == h->table) { free(h); return NULL; } /*oom*/ memset(h->table, 0, size * sizeof(struct entry *)); h->tablelength = size; @@ -110,7 +111,7 @@ hashtable_expand(struct hashtable *h) if (h->primeindex == (prime_table_length - 1)) return 0; newsize = primes[++(h->primeindex)]; - newtable = (struct entry **)malloc(sizeof(struct entry*) * newsize); + newtable = (struct entry **)zap_malloc(sizeof(struct entry*) * newsize); if (NULL != newtable) { memset(newtable, 0, newsize * sizeof(struct entry *)); @@ -178,7 +179,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags) * element may be ok. Next time we insert, we'll try expanding again.*/ hashtable_expand(h); } - e = (struct entry *)malloc(sizeof(struct entry)); + e = (struct entry *)zap_malloc(sizeof(struct entry)); if (NULL == e) { --(h->entrycount); return 0; } /*oom*/ e->h = hash(h,k); index = indexFor(h->tablelength,e->h); diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index bdd97ca591..726cee3b09 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -753,19 +753,19 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); \brief Allocate uninitialized memory \command chunksize the chunk size */ -#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize); +#define zap_malloc(chunksize) g_zap_mem_handler.malloc(g_zap_mem_handler.pool, chunksize) /*! \brief Allocate initialized memory \command chunksize the chunk size */ -#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize); +#define zap_calloc(elements, chunksize) g_zap_mem_handler.calloc(g_zap_mem_handler.pool, elements, chunksize) /*! \brief Free chunk of memory \command chunksize the chunk size */ -#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk); +#define zap_free(chunk) g_zap_mem_handler.free(g_zap_mem_handler.pool, chunk) /*! \brief Free a pointer and set it to NULL unless it already is NULL diff --git a/libs/freetdm/src/isdn/Q921.c b/libs/freetdm/src/isdn/Q921.c index 0496e09f5c..9cfd08a07c 100644 --- a/libs/freetdm/src/isdn/Q921.c +++ b/libs/freetdm/src/isdn/Q921.c @@ -79,6 +79,7 @@ #include #include +#include "openzap.h" #include "Q921.h" #include "Q921priv.h" #include "mfifo.h" @@ -397,7 +398,7 @@ int Q921_InitTrunk(L2TRUNK trunk, /* * Allocate space for per-link context(s) */ - trunk->context = malloc(numlinks * sizeof(struct Q921_Link)); + trunk->context = zap_malloc(numlinks * sizeof(struct Q921_Link)); if(!trunk->context) return -1; diff --git a/libs/freetdm/src/libteletone_generate.c b/libs/freetdm/src/libteletone_generate.c index 1d5d696af2..d0ae2b01e3 100644 --- a/libs/freetdm/src/libteletone_generate.c +++ b/libs/freetdm/src/libteletone_generate.c @@ -34,6 +34,7 @@ */ #include +#include "openzap.h" #define SMAX 32767 #define SMIN -32768 @@ -273,7 +274,7 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone static char *my_strdup (const char *s) { size_t len = strlen (s) + 1; - void *new = malloc (len); + void *new = zap_malloc(len); if (new == NULL) { return NULL; diff --git a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c index 3978c94106..4da3e2e564 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c +++ b/libs/freetdm/src/ozmod/ozmod_analog/ozmod_analog.c @@ -122,7 +122,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_configure_span) return ZAP_FAIL; } - analog_data = malloc(sizeof(*analog_data)); + analog_data = zap_malloc(sizeof(*analog_data)); assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c index 4468e4b92d..53bf1a000f 100644 --- a/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c +++ b/libs/freetdm/src/ozmod/ozmod_analog_em/ozmod_analog_em.c @@ -106,7 +106,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_analog_em_configure_span) return ZAP_FAIL; } - analog_data = malloc(sizeof(*analog_data)); + analog_data = zap_malloc(sizeof(*analog_data)); assert(analog_data != NULL); memset(analog_data, 0, sizeof(*analog_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c index d054bd08d1..a92877ca14 100644 --- a/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c +++ b/libs/freetdm/src/ozmod/ozmod_isdn/ozmod_isdn.c @@ -2263,7 +2263,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) return ZAP_FAIL; } - isdn_data = malloc(sizeof(*isdn_data)); + isdn_data = zap_malloc(sizeof(*isdn_data)); assert(isdn_data != NULL); memset(isdn_data, 0, sizeof(*isdn_data)); @@ -2333,7 +2333,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_isdn_configure_span) if (isdn_data->mode == Q931_NT) { zap_isdn_bchan_data_t *data; - data = malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t)); + data = zap_malloc((span->chan_count - 1) * sizeof(zap_isdn_bchan_data_t)); if (!data) { return ZAP_FAIL; } diff --git a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c index a8e3fea6f7..e80de2686d 100644 --- a/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c +++ b/libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c @@ -1272,7 +1272,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_libpri_configure_span) } #endif - isdn_data = malloc(sizeof(*isdn_data)); + isdn_data = zap_malloc(sizeof(*isdn_data)); assert(isdn_data != NULL); memset(isdn_data, 0, sizeof(*isdn_data)); diff --git a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c index 154c1618ff..536110c32a 100644 --- a/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c +++ b/libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c @@ -156,7 +156,7 @@ static ZIO_CONFIGURE_FUNCTION(pika_configure) int ok = 1; if (!(profile = (pika_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = malloc(sizeof(*profile)); + profile = zap_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); profile->ec_config = globals.ec_config; @@ -348,7 +348,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa if (span->mod_data) { span_data = span->mod_data; } else { - span_data = malloc(sizeof(*span_data)); + span_data = zap_malloc(sizeof(*span_data)); assert(span_data != NULL); memset(span_data, 0, sizeof(*span_data)); span_data->boardno = boardno; @@ -376,7 +376,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa zap_channel_t *chan; pika_chan_data_t *chan_data = NULL; - chan_data = malloc(sizeof *chan_data); + chan_data = zap_malloc(sizeof *chan_data); assert(chan_data); memset(chan_data, 0, sizeof(*chan_data)); zap_span_add_channel(span, 0, type, &chan); diff --git a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c index 9683aa57b2..837a8887b7 100644 --- a/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c +++ b/libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c @@ -32,7 +32,6 @@ */ #include -#include #include #include "openzap.h" @@ -738,7 +737,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) } openr2_log_level_t tmplevel; char *clevel; - char *logval = malloc(strlen(val)+1); /* alloca man page scared me, so better to use good ol' malloc */ + char *logval = zap_malloc(strlen(val)+1); /* alloca man page scared me, so better to use good ol' malloc */ if (!logval) { zap_log(ZAP_LOG_WARNING, "Ignoring R2 logging parameter: '%s', failed to alloc memory\n", val); continue; @@ -811,14 +810,14 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) return ZAP_FAIL; } - r2data = malloc(sizeof(*r2data)); + r2data = zap_malloc(sizeof(*r2data)); if (!r2data) { snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate R2 data."); return ZAP_FAIL; } memset(r2data, 0, sizeof(*r2data)); - spanpvt = malloc(sizeof(*spanpvt)); + spanpvt = zap_malloc(sizeof(*spanpvt)); if (!spanpvt) { snprintf(span->last_error, sizeof(span->last_error), "Failed to allocate private span data container."); goto fail; @@ -862,7 +861,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span) openr2_chan_set_log_level(r2chan, r2conf.loglevel); } - r2call = malloc(sizeof(*r2call)); + r2call = zap_malloc(sizeof(*r2call)); if (!r2call) { snprintf(span->last_error, sizeof(span->last_error), "Cannot create all R2 call data structures for the span."); zap_safe_free(r2chan); diff --git a/libs/freetdm/src/uart.c b/libs/freetdm/src/uart.c index 5e0dd85350..14f066da59 100644 --- a/libs/freetdm/src/uart.c +++ b/libs/freetdm/src/uart.c @@ -32,6 +32,7 @@ * 2005 06 11 R. Krten created */ +#include #include #include #include @@ -76,7 +77,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr) { dsp_uart_handle_t *handle; - handle = malloc(sizeof (*handle)); + handle = zap_malloc(sizeof (*handle)); if (handle) { memset(handle, 0, sizeof (*handle)); diff --git a/libs/freetdm/src/zap_buffer.c b/libs/freetdm/src/zap_buffer.c index 0e2279d7e3..bd8b0cc307 100644 --- a/libs/freetdm/src/zap_buffer.c +++ b/libs/freetdm/src/zap_buffer.c @@ -53,12 +53,12 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo { zap_buffer_t *new_buffer; - new_buffer = malloc(sizeof(*new_buffer)); + new_buffer = zap_malloc(sizeof(*new_buffer)); if (new_buffer) { memset(new_buffer, 0, sizeof(*new_buffer)); if (start_len) { - new_buffer->data = malloc(start_len); + new_buffer->data = zap_malloc(start_len); if (!new_buffer->data) { free(new_buffer); return ZAP_MEMERR; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index cc4ebb7f42..4a20acf65f 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -35,8 +35,6 @@ #ifndef WIN32 #endif #include "openzap.h" -//#include "zap_isdn.h" -//#include "zap_ss7_boost.h" #include #ifdef WIN32 #include @@ -426,7 +424,7 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s zap_mutex_lock(globals.mutex); if (globals.span_index < ZAP_MAX_SPANS_INTERFACE) { - new_span = malloc(sizeof(*new_span)); + new_span = zap_malloc(sizeof(*new_span)); assert(new_span); memset(new_span, 0, sizeof(*new_span)); status = zap_mutex_create(&new_span->mutex); @@ -554,7 +552,7 @@ OZ_DECLARE(zap_status_t) zap_span_add_channel(zap_span_t *span, zap_socket_t soc zap_channel_t *new_chan = span->channels[++span->chan_count]; if (!new_chan) { - if (!(new_chan = malloc(sizeof(*new_chan)))) { + if (!(new_chan = zap_malloc(sizeof(*new_chan)))) { return ZAP_FAIL; } span->channels[span->chan_count] = new_chan; @@ -3112,7 +3110,7 @@ OZ_DECLARE(int) zap_vasprintf(char **ret, const char *fmt, va_list ap) /* code f len = vsnprintf(tmp, 0, fmt, ap2); - if (len > 0 && (buf = malloc((buflen = (size_t) (len + 1)))) != NULL) { + if (len > 0 && (buf = zap_malloc((buflen = (size_t) (len + 1)))) != NULL) { len = vsnprintf(buf, buflen, fmt, ap); *ret = buf; } else { diff --git a/libs/freetdm/src/zap_m3ua.c b/libs/freetdm/src/zap_m3ua.c index 50736b75e4..8e572c92d7 100644 --- a/libs/freetdm/src/zap_m3ua.c +++ b/libs/freetdm/src/zap_m3ua.c @@ -399,7 +399,7 @@ static ZIO_CONFIGURE_FUNCTION(m3ua_configure) int ok = 1; if (!(profile = (m3ua_channel_profile_t *) hashtable_search(globals.profile_hash, (char *)category))) { - profile = malloc(sizeof(*profile)); + profile = zap_malloc(sizeof(*profile)); memset(profile, 0, sizeof(*profile)); zap_set_string(profile->name, category); hashtable_insert(globals.profile_hash, (void *)profile->name, profile); diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index fa302e56a6..d4a12f4186 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -99,7 +99,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun zap_thread_t *thread = NULL; zap_status_t status = ZAP_FAIL; - if (!func || !(thread = (zap_thread_t *)malloc(sizeof(zap_thread_t)))) { + if (!func || !(thread = (zap_thread_t *)zap_malloc(sizeof(zap_thread_t)))) { goto done; } @@ -149,7 +149,7 @@ OZ_DECLARE(zap_status_t) zap_mutex_create(zap_mutex_t **mutex) #endif zap_mutex_t *check = NULL; - check = (zap_mutex_t *)malloc(sizeof(**mutex)); + check = (zap_mutex_t *)zap_malloc(sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 @@ -242,7 +242,7 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap return ZAP_NOTIMPL; #endif - condition = malloc(sizeof(*condition)); + condition = zap_malloc(sizeof(*condition)); if (!condition) { return ZAP_FAIL; }