]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
replaced a ton of free or strdup calls for zap_safe_free and zap_strdup
authorMoises Silva <moy@sangoma.com>
Mon, 16 Nov 2009 14:52:02 +0000 (14:52 +0000)
committerMoises Silva <moy@sangoma.com>
Mon, 16 Nov 2009 14:52:02 +0000 (14:52 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@864 a93c3328-9c30-0410-af19-c9cd2b2d52af

16 files changed:
libs/freetdm/src/fsk.c
libs/freetdm/src/hashtable.c
libs/freetdm/src/hashtable_itr.c
libs/freetdm/src/include/openzap.h
libs/freetdm/src/libteletone_generate.c
libs/freetdm/src/ozmod/ozmod_libpri/ozmod_libpri.c
libs/freetdm/src/ozmod/ozmod_pika/ozmod_pika.c
libs/freetdm/src/ozmod/ozmod_r2/ozmod_r2.c
libs/freetdm/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c
libs/freetdm/src/ozmod/ozmod_zt/ozmod_zt.c
libs/freetdm/src/uart.c
libs/freetdm/src/zap_buffer.c
libs/freetdm/src/zap_dso.c
libs/freetdm/src/zap_io.c
libs/freetdm/src/zap_m3ua.c
libs/freetdm/src/zap_threadmutex.c

index f55d42155970d63e21fcf42aa619a549f7e3c347..16a1bcb7d4f03a5a8f9e38d0bdf22851ab4fc8e4 100644 (file)
@@ -226,13 +226,13 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle)
 
        for (i = 0; i < 4; i++) {
                if ((*handle)->correlates[i] != NULL) {
-                       free((*handle)->correlates[i]);
+                       zap_safe_free((*handle)->correlates[i]);
                        (*handle)->correlates[i] = NULL;
                }
        }
 
        if ((*handle)->buffer != NULL) {
-               free((*handle)->buffer);
+               zap_safe_free((*handle)->buffer);
                (*handle)->buffer = NULL;
        }
 
@@ -241,7 +241,7 @@ void dsp_fsk_destroy(dsp_fsk_handle_t **handle)
                dsp_uart_destroy(dhandle);
        }
 
-       free(*handle);
+       zap_safe_free(*handle);
        *handle = NULL;
 }
 
index 415dda7d8dbe51f65bbfe9f07ece17b60d1cf80a..15ec9014f4dfc40ac7d1cd1a03815b2af625b8fa 100644 (file)
@@ -73,7 +73,7 @@ create_hashtable(unsigned int minsize,
     h = (struct hashtable *)zap_malloc(sizeof(struct hashtable));
     if (NULL == h) return NULL; /*oom*/
     h->table = (struct entry **)zap_malloc(sizeof(struct entry*) * size);
-    if (NULL == h->table) { free(h); return NULL; } /*oom*/
+    if (NULL == h->table) { zap_safe_free(h); return NULL; } /*oom*/
     memset(h->table, 0, size * sizeof(struct entry *));
     h->tablelength  = size;
     h->primeindex   = pindex;
@@ -125,7 +125,7 @@ hashtable_expand(struct hashtable *h)
                                        newtable[index] = e;
                                }
                        }
-                       free(h->table);
+                       zap_safe_free(h->table);
                        h->table = newtable;
                }
     /* Plan B: realloc instead */
@@ -236,7 +236,7 @@ hashtable_remove(struct hashtable *h, void *k)
                                        if (e->flags & HASHTABLE_FLAG_FREE_KEY) {
                                                freekey(e->k);
                                        }
-                                       free(e);
+                                       zap_safe_free(e);
                                        return v;
                                }
                        pE = &(e->next);
@@ -258,11 +258,11 @@ hashtable_destroy(struct hashtable *h)
         {
             e = table[i];
             while (NULL != e)
-                               { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) free(f->v); free(f); }
+                               { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) zap_safe_free(f->v); zap_safe_free(f); }
         }
     
-    free(h->table);
-    free(h);
+    zap_safe_free(h->table);
+    zap_safe_free(h);
 }
 
 OZ_DECLARE(struct hashtable_iterator *) hashtable_next(struct hashtable_iterator *i)
index cb8165dc919b3ec7ae053154ad823d29e6f93f23..ab5e1ce0c862295538c9dfcb737f2b6170cea232 100644 (file)
@@ -138,7 +138,7 @@ hashtable_iterator_remove(struct hashtable_itr *itr)
     remember_parent = itr->parent;
     ret = hashtable_iterator_advance(itr);
     if (itr->parent == remember_e) { itr->parent = remember_parent; }
-    free(remember_e);
+    zap_safe_free(remember_e);
     return ret;
 }
 
index 726cee3b0969fcc119972efdb9f05944820edc77..bc6b0a9dd3b939134d7ed80cf9e85282a2b99bdf 100644 (file)
@@ -625,6 +625,9 @@ OZ_DECLARE(zap_status_t) zap_queue_wait(zap_queue_t *queue, int ms);
 /*! destroy the queue */ 
 OZ_DECLARE(zap_status_t) zap_queue_destroy(zap_queue_t **queue);
 
+/* Duplicate string */
+OZ_DECLARE(char *) zap_strdup(const char *str);
+
 OZ_DECLARE(zap_size_t) zap_fsk_modulator_generate_bit(zap_fsk_modulator_t *fsk_trans, int8_t bit, int16_t *buf, zap_size_t buflen);
 OZ_DECLARE(int32_t) zap_fsk_modulator_generate_carrier_bits(zap_fsk_modulator_t *fsk_trans, uint32_t bits);
 OZ_DECLARE(void) zap_fsk_modulator_generate_chan_sieze(zap_fsk_modulator_t *fsk_trans);
index bb41224c9a1da4a76205f52fc74038d0f1afaa27..c261772f924855ec520e5f2d1aadb26bf6e56f01 100644 (file)
@@ -142,7 +142,7 @@ TELETONE_API(int) teletone_init_session(teletone_generation_session_t *ts, int b
 TELETONE_API(int) teletone_destroy_session(teletone_generation_session_t *ts)
 {
        if (ts->buffer) {
-               free(ts->buffer);
+               zap_safe_free(ts->buffer);
                ts->buffer = NULL;
                ts->samples = 0;
        }
@@ -270,19 +270,6 @@ TELETONE_API(int) teletone_mux_tones(teletone_generation_session_t *ts, teletone
        return ts->samples;
 }
 
-/* don't ask */
-static char *my_strdup (const char *s)
-{
-       size_t len = strlen (s) + 1;
-       void *new = zap_malloc(len);
-       
-       if (new == NULL) {
-               return NULL;
-       }
-
-       return (char *) memcpy (new, s, len);
-}
-
 TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cmd)
 {
        char *data = NULL, *cur = NULL, *end = NULL;
@@ -293,7 +280,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm
        }
 
        do {
-               if (!(data = my_strdup(cmd))) {
+               if (!(data = zap_strdup(cmd))) {
                        return -1;
                }
 
@@ -442,7 +429,7 @@ TELETONE_API(int) teletone_run(teletone_generation_session_t *ts, const char *cm
                        }
                }
        bottom:
-               free(data);
+               zap_safe_free(data);
                data = NULL;
                if (ts->LOOPS > 0) {
                        ts->LOOPS--;
index e80de2686d0d54df49b319a95f29224975fb898c..ec92684a578a9204ac8983de8d4854e91b1882ad 100644 (file)
@@ -210,7 +210,7 @@ static ZIO_API_FUNCTION(zap_libpri_api)
     int argc = 0;
        
        if (data) {
-               mycmd = strdup(data);
+               mycmd = zap_strdup(data);
                argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
        }
 
index 536110c32a2427eca74b94b6e3bf4bbf6fe6ae59..2932a342e742a21eed0eeefef4b75b1850ea91cb 100644 (file)
@@ -358,7 +358,7 @@ static unsigned pika_open_range(zap_span_t *span, unsigned boardno, unsigned spa
                if (status != PK_SUCCESS) {
                        zap_log(ZAP_LOG_ERROR, "Error: PKH_QUEUE_Create failed(%s)!\n",
                                        PKH_ERROR_GetText(status, error_text, sizeof(error_text)));
-                       free(span_data);
+                       zap_safe_free(span_data);
                        return 0;
                }
 
@@ -605,7 +605,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span)
 
        assert(str != NULL);
 
-       mydata = strdup(str);
+       mydata = zap_strdup(str);
        assert(mydata != NULL);
 
        if ((profile_name = strchr(mydata, '@'))) {
@@ -668,7 +668,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(pika_configure_span)
 
        }
        
-       free(mydata);
+       zap_safe_free(mydata);
 
        return configured;
 }
@@ -1211,7 +1211,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(pika_span_destroy)
        
        if (span_data) {
                PKH_QUEUE_Destroy(span_data->event_queue);
-               free(span_data);
+               zap_safe_free(span_data);
        }
        
        return ZAP_SUCCESS;
index 837a8887b75d9814f4eb8f9cba47de1d1f87e05c..8000aa2a6431800d97debf0c25122148c0dc08b5 100644 (file)
@@ -752,7 +752,7 @@ static ZIO_SIG_CONFIGURE_FUNCTION(zap_r2_configure_span)
                                r2conf.loglevel |= tmplevel;
                                zap_log(ZAP_LOG_DEBUG, "Configuring R2 span %d with loglevel %s\n", span->span_id, clevel);
                        }
-                       free(logval);
+                       zap_safe_free(logval);
                } else if (!strcasecmp(var, "advanced_protocol_file")) {
                        if (!(val = va_arg(ap, char *))) {
                                break;
@@ -1182,7 +1182,7 @@ static ZIO_API_FUNCTION(zap_r2_api)
        int argc = 0;
 
        if (data) {
-               mycmd = strdup(data);
+               mycmd = zap_strdup(data);
                argc = zap_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
        }
 
index a275acc352a218ecda78dd739927d0843bda7896..3d681985fb6b63daf59d7fd02da3b253bcfb8a53 100644 (file)
@@ -397,7 +397,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span)
        assert(str != NULL);
        
 
-       mydata = strdup(str);
+       mydata = zap_strdup(str);
        assert(mydata != NULL);
 
 
@@ -447,7 +447,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(wanpipe_configure_span)
 
        }
        
-       free(mydata);
+       zap_safe_free(mydata);
 
        return configured;
 }
index b8788d2a581ba4eacde229787c03752cbe1128df..bbd64352f454215ef3e9b87a27ab159b12fe57c4 100644 (file)
@@ -452,7 +452,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span)
        assert(str != NULL);
        
 
-       mydata = strdup(str);
+       mydata = zap_strdup(str);
        assert(mydata != NULL);
 
 
@@ -493,7 +493,7 @@ static ZIO_CONFIGURE_SPAN_FUNCTION(zt_configure_span)
 
        }
        
-       free(mydata);
+       zap_safe_free(mydata);
 
        return configured;
 
index 14f066da5977ff554b82135fa93d36b49c5402f0..b3728e6fc82e2f18aa41d3d0a21506c0b4fb45f6 100644 (file)
@@ -90,7 +90,7 @@ dsp_uart_handle_t *dsp_uart_create(dsp_uart_attr_t *attr)
 void dsp_uart_destroy(dsp_uart_handle_t **handle)
 {
        if (*handle) {
-               free(*handle);
+               zap_safe_free(*handle);
                *handle = NULL;
        }
 }
index bd8b0cc3071265e3786bd623c80d26a3f9c673ea..11a7c03d29370c703127a6e9e3a97ba26d0566e7 100644 (file)
@@ -60,7 +60,7 @@ OZ_DECLARE(zap_status_t) zap_buffer_create(zap_buffer_t **buffer, zap_size_t blo
                if (start_len) {
                        new_buffer->data = zap_malloc(start_len);
                        if (!new_buffer->data) {
-                               free(new_buffer);
+                               zap_safe_free(new_buffer);
                                return ZAP_MEMERR;
                        }
                        memset(new_buffer->data, 0, start_len);
@@ -283,8 +283,8 @@ OZ_DECLARE(zap_size_t) zap_buffer_zwrite(zap_buffer_t *buffer, const void *data,
 OZ_DECLARE(void) zap_buffer_destroy(zap_buffer_t **buffer)
 {
        if (*buffer) {
-               free((*buffer)->data);
-               free(*buffer);
+               zap_safe_free((*buffer)->data);
+               zap_safe_free(*buffer);
        }
 
        *buffer = NULL;
index ead40e7c4b1b466188b5fc719d537976277421c2..eefe6e819cd5adc0d4fbc69d5ce7d20f21281735 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include "openzap.h"
 #include "zap_dso.h"
 #include <stdlib.h>
 #include <string.h>
@@ -46,7 +47,7 @@ zap_dso_lib_t zap_dso_open(const char *path, char **err) {
                DWORD error = GetLastError();
                char tmp[80];
                sprintf(tmp, "dll open error [%ul]\n", error);
-               *err = _strdup(tmp);
+               *err = zap_strdup(tmp);
        }
 
        return lib;
@@ -58,7 +59,7 @@ void* zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) {
                DWORD error = GetLastError();
                char tmp[80];
                sprintf(tmp, "dll sym error [%ul]\n", error);
-               *err = _strdup(tmp);
+               *err = zap_strdup(tmp);
        }
        return (void *)(intptr_t)func; // this should really be addr - zap_dso_func_data
 }
@@ -87,7 +88,7 @@ void zap_dso_destroy(zap_dso_lib_t *lib) {
 zap_dso_lib_t zap_dso_open(const char *path, char **err) {
        void *lib = dlopen(path, RTLD_NOW | RTLD_LOCAL);
        if (lib == NULL) {
-               *err = strdup(dlerror());
+               *err = zap_strdup(dlerror());
        }
        return lib;
 }
@@ -95,7 +96,7 @@ zap_dso_lib_t zap_dso_open(const char *path, char **err) {
 void *zap_dso_func_sym(zap_dso_lib_t lib, const char *sym, char **err) {
        void *func = dlsym(lib, sym);
        if (!func) {
-               *err = strdup(dlerror());
+               *err = zap_strdup(dlerror());
        }
        return func;
 }
index d0a6aaf69d0f67a7a15cda595a01b82821c5ffcd..a8e73295586f213ac562f7e260770351a0473b2d 100644 (file)
@@ -452,7 +452,7 @@ OZ_DECLARE(zap_status_t) zap_span_create(zap_io_interface_t *zio, zap_span_t **s
                        snprintf(buf, sizeof(buf), "span%d", new_span->span_id);
                        name = buf;
                }
-               new_span->name = strdup(name);
+               new_span->name = zap_strdup(name);
                zap_span_add(new_span);
                *span = new_span;
                status = ZAP_SUCCESS;
@@ -2306,8 +2306,8 @@ OZ_DECLARE(zap_status_t) zap_channel_add_var(zap_channel_t *zchan, const char *v
                return ZAP_FAIL;
        }
 
-       t_name = strdup(var_name);
-       t_val = strdup(value);
+       t_name = zap_strdup(var_name);
+       t_val = zap_strdup(value);
 
        if(hashtable_insert(zchan->variable_hash, t_name, t_val, HASHTABLE_FLAG_FREE_KEY | HASHTABLE_FLAG_FREE_VALUE)) {
                return ZAP_SUCCESS;
@@ -2336,7 +2336,7 @@ OZ_DECLARE(char *) zap_api_execute(const char *type, const char *cmd)
        char *rval = NULL;
 
        if (type && !cmd) {
-               dup = strdup(type);
+               dup = zap_strdup(type);
                if ((p = strchr(dup, ' '))) {
                        *p++ = '\0';
                        cmd = p;
@@ -2440,7 +2440,7 @@ static zap_status_t load_config(void)
                                }
 
                                if (zap_span_create(zio, &span, name) == ZAP_SUCCESS) {
-                                       span->type = strdup(type);
+                                       span->type = zap_strdup(type);
                                        d = 0;
 
                                        zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type);
@@ -2534,7 +2534,7 @@ static zap_status_t load_config(void)
                        } else if (!strcasecmp(var, "cas-channel")) {
                                configured += zio->configure_span(span, val, ZAP_CHAN_TYPE_CAS, name, number);  
                        } else if (!strcasecmp(var, "dtmf_hangup")) {
-                               span->dtmf_hangup = strdup(val);
+                               span->dtmf_hangup = zap_strdup(val);
                                span->dtmf_hangup_len = strlen(val);
                        } else {
                                zap_log(ZAP_LOG_ERROR, "unknown span variable '%s'\n", var);
@@ -2849,7 +2849,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void)
                                                if (zap_test_flag(cur_chan, ZAP_CHANNEL_CONFIGURED)) {
                                                        zap_channel_destroy(cur_chan);
                                                }
-                                               free(cur_chan);
+                                               zap_safe_free(cur_chan);
                                                cur_chan = NULL;
                                        }
                                }
@@ -2866,7 +2866,7 @@ OZ_DECLARE(zap_status_t) zap_global_destroy(void)
                        hashtable_remove(globals.span_hash, (void *)cur_span->name);
                        zap_safe_free(cur_span->type);
                        zap_safe_free(cur_span->name);
-                       free(cur_span);
+                       zap_safe_free(cur_span);
                        cur_span = NULL;
                }
        }
@@ -3157,7 +3157,7 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha
                                end = handle->end;
                        } else {
                                zap_log(ZAP_LOG_CRIT, "Memory Error!\n");
-                               free(data);
+                               zap_safe_free(data);
                                return ZAP_FAIL;
                        }
                }
@@ -3170,12 +3170,23 @@ OZ_DECLARE_NONSTD(zap_status_t) zap_console_stream_write(zap_stream_handle_t *ha
                        handle->data_len = strlen(buf);
                        handle->end = (uint8_t *) (handle->data) + handle->data_len;
                }
-               free(data);
+               zap_safe_free(data);
        }
 
        return ret ? ZAP_FAIL : ZAP_SUCCESS;
 }
 
+OZ_DECLARE(char *) zap_strdup(const char *str)
+{
+       zap_size_t len = strlen(str) + 1;
+       void *new = zap_malloc(len);
+
+       if (!new) {
+               return NULL;
+       }
+
+       return (char *)memcpy(new, str, len);
+}
 
 
 /* For Emacs:
index 8e572c92d7f5d399cbc9d357d17849bbc501e191..bcc0e0559dd2b16facb8dffd15eb184ab6b28ace 100644 (file)
@@ -487,7 +487,7 @@ static ZIO_SPAN_DESTROY_FUNCTION(m3ua_span_destroy)
        m3ua_span_data_t *span_data = (m3ua_span_data_t *) span->mod_data;
        
        if (span_data) {
-               free(span_data);
+               zap_safe_free(span_data);
        }
        
        return ZAP_SUCCESS;
@@ -513,7 +513,7 @@ static ZIO_CHANNEL_DESTROY_FUNCTION(m3ua_channel_destroy)
        zap_safe_free(chan_data);
        
        if (span_data) {
-               free(span_data);
+               zap_safe_free(span_data);
        }
        
                        
index d4a12f4186b84a3ab9f56c9b2fc704fae3f07f87..1fb3c479f6c624aaaf13c0b575fa448dfe02fe2c 100644 (file)
@@ -84,7 +84,7 @@ static void * ZAP_THREAD_CALLING_CONVENTION thread_launch(void *args)
 #ifndef WIN32
        pthread_attr_destroy(&thread->attribute);
 #endif
-       free(thread);
+       zap_safe_free(thread);
 
        return exit_val;
 }
@@ -134,7 +134,7 @@ OZ_DECLARE(zap_status_t) zap_thread_create_detached_ex(zap_thread_function_t fun
 
  fail:
        if (thread) {
-               free(thread);
+               zap_safe_free(thread);
        }
  done:
        return status;
@@ -192,7 +192,7 @@ OZ_DECLARE(zap_status_t) zap_mutex_destroy(zap_mutex_t **mutex)
        if (pthread_mutex_destroy(&mp->mutex))
                return ZAP_FAIL;
 #endif
-       free(mp);
+       zap_safe_free(mp);
        return ZAP_SUCCESS;
 }