core: Don't allow free to mean ast_free (and malloc, etc..).
authorWalter Doekes <walter+asterisk@wjd.nu>
Fri, 26 Sep 2014 14:41:38 +0000 (14:41 +0000)
committerWalter Doekes <walter+asterisk@wjd.nu>
Fri, 26 Sep 2014 14:41:38 +0000 (14:41 +0000)
This gets rid of most old libc free/malloc/realloc and replaces them
with ast_free and friends. When compiling with MALLOC_DEBUG you'll
notice it when you're mistakenly using one of the libc variants. For
the legacy cases you can define WRAP_LIBC_MALLOC before including
asterisk.h.

Even better would be if the errors were also enabled when compiling
without MALLOC_DEBUG, but that's a slightly more invasive header
file change.

Those compiling addons/format_mp3 will need to rerun
./contrib/scripts/get_mp3_source.sh.

ASTERISK-24348 #related
Review: https://reviewboard.asterisk.org/r/4015/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@423978 65c4cc65-6c06-0410-ace0-fbb531ad65f3

44 files changed:
addons/app_mysql.c
addons/chan_ooh323.c
addons/ooh323c/src/context.c
addons/ooh323c/src/errmgmt.c
addons/ooh323c/src/memheap.c
addons/ooh323c/src/ooCalls.c
addons/ooh323c/src/ooCmdChannel.c
addons/ooh323c/src/ooStackCmds.c
addons/ooh323c/src/oochannels.c
addons/ooh323c/src/printHandler.c
addons/ooh323cDriver.c
apps/app_jack.c
apps/app_queue.c
cel/cel_tds.c
channels/chan_console.c
channels/chan_mgcp.c
channels/chan_skinny.c
contrib/scripts/get_mp3_source.sh
funcs/func_curl.c
include/asterisk/astmm.h
main/abstract_jb.c
main/acl.c
main/app.c
main/ast_expr2.c
main/ast_expr2.y
main/ast_expr2f.c
main/autoservice.c
main/file.c
main/hashtab.c
main/loader.c
main/tdd.c
pbx/pbx_config.c
res/ael/ael.flex
res/ael/ael.tab.c
res/ael/ael.y
res/ael/ael_lex.c
res/ael/pval.c
res/res_config_ldap.c
res/res_phoneprov.c
res/res_pktccops.c
res/res_rtp_asterisk.c
res/res_smdi.c
tests/test_dlinklists.c
utils/extconf.c

index 298ed9d..6901daf 100644 (file)
@@ -218,7 +218,7 @@ static int add_identifier(struct ast_channel *chan, int identifier_type, void *d
                ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
                return -1;
        } else {
-               i = malloc(sizeof(*i));
+               i = ast_malloc(sizeof(*i));
                AST_LIST_TRAVERSE(headp, j, entries) {
                        if (j->identifier > maxidentifier) {
                                maxidentifier = j->identifier;
@@ -247,7 +247,7 @@ static int del_identifier(int identifier, int identifier_type)
                        if ((i->identifier == identifier) &&
                            (i->identifier_type == identifier_type)) {
                                AST_LIST_REMOVE(headp, i, entries);
-                               free(i);
+                               ast_free(i);
                                found = 1;
                                break;
                        }
index b0fa01f..8fd02cc 100644 (file)
@@ -538,7 +538,7 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
 
        pvt->call_reference = callref;
        if (callToken)
-               pvt->callToken = strdup(callToken);
+               pvt->callToken = ast_strdup(callToken);
 
        /* whether to use gk for this call */
        if (gRasGkMode == RasNoGatekeeper)
@@ -645,8 +645,8 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca
        }
 
        if (peer) {
-               p->username = strdup(peer->name);
-               p->host = strdup(peer->ip);
+               p->username = ast_strdup(peer->name);
+               p->host = ast_strdup(peer->ip);
                p->port = peer->port;
                /* Disable gk as we are going to call a known peer*/
                /* OO_SETFLAG(p->flags, H323_DISABLEGK); */
@@ -707,9 +707,9 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca
                p->directrtp = gDirectRTP;
                p->earlydirect = gEarlyDirect;
 
-               p->username = strdup(dest);
+               p->username = ast_strdup(dest);
 
-               p->host = strdup(dest);
+               p->host = ast_strdup(dest);
                if (port > 0) {
                        p->port = port;
                }
@@ -964,22 +964,22 @@ static int ooh323_call(struct ast_channel *ast, const char *dest, int timeout)
        ast_mutex_lock(&p->lock);
        ast_set_flag(p, H323_OUTGOING);
        if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
-               free(p->callerid_num);
-               p->callerid_num = strdup(ast_channel_connected(ast)->id.number.str);
+               ast_free(p->callerid_num);
+               p->callerid_num = ast_strdup(ast_channel_connected(ast)->id.number.str);
        }
 
        if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
-               free(p->callerid_name);
-               p->callerid_name = strdup(ast_channel_connected(ast)->id.name.str);
+               ast_free(p->callerid_name);
+               p->callerid_name = ast_strdup(ast_channel_connected(ast)->id.name.str);
        } else if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
-               free(p->callerid_name);
-               p->callerid_name = strdup(ast_channel_connected(ast)->id.number.str);
+               ast_free(p->callerid_name);
+               p->callerid_name = ast_strdup(ast_channel_connected(ast)->id.number.str);
        } else {
                ast_channel_connected(ast)->id.name.valid = 1;
-               free(ast_channel_connected(ast)->id.name.str);
-               ast_channel_connected(ast)->id.name.str = strdup(gCallerID);
-               free(p->callerid_name);
-               p->callerid_name = strdup(ast_channel_connected(ast)->id.name.str);
+               ast_free(ast_channel_connected(ast)->id.name.str);
+               ast_channel_connected(ast)->id.name.str = ast_strdup(gCallerID);
+               ast_free(p->callerid_name);
+               p->callerid_name = ast_strdup(ast_channel_connected(ast)->id.name.str);
        }
 
        /* Retrieve vars */
@@ -992,7 +992,7 @@ static int ooh323_call(struct ast_channel *ast, const char *dest, int timeout)
        if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323DIALEDDIGITS"))) {
                ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits));
                if(!p->callerid_num)
-                       p->callerid_num = strdup(val);
+                       p->callerid_num = ast_strdup(val);
        }
 
        if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) {
@@ -1113,7 +1113,7 @@ static int ooh323_answer(struct ast_channel *ast)
        if (p) {
 
                ast_mutex_lock(&p->lock);
-               callToken = (p->callToken ? strdup(p->callToken) : NULL);
+               callToken = (p->callToken ? ast_strdup(p->callToken) : NULL);
                if (ast_channel_state(ast) != AST_STATE_UP) {
                        ast_channel_lock(ast);
                        if (!p->alertsent) {
@@ -1132,7 +1132,7 @@ static int ooh323_answer(struct ast_channel *ast)
                        ooAnswerCall(p->callToken);
                }
                if (callToken) {
-                       free(callToken);
+                       ast_free(callToken);
                }
                ast_mutex_unlock(&p->lock);
        }
@@ -1239,7 +1239,7 @@ static int ooh323_indicate(struct ast_channel *ast, int condition, const void *d
        if (!p) return -1;
 
        ast_mutex_lock(&p->lock);
-       callToken = (p->callToken ? strdup(p->callToken) : NULL);
+       callToken = (p->callToken ? ast_strdup(p->callToken) : NULL);
        ast_mutex_unlock(&p->lock);
 
        if (!callToken) {
@@ -1409,7 +1409,7 @@ static int ooh323_indicate(struct ast_channel *ast, int condition, const void *d
                ast_verb(0, "++++  ooh323_indicate %d on %s is %d\n", condition, callToken, res);
        }
 
-       free(callToken);
+       ast_free(callToken);
        return res;
 }
 
@@ -1815,25 +1815,25 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
   
 
        if (call->remoteDisplayName) {
-               p->callerid_name = strdup(call->remoteDisplayName);
+               p->callerid_name = ast_strdup(call->remoteDisplayName);
        }
 
        if (ooCallGetCallingPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK) {
-               p->callerid_num = strdup(number);
+               p->callerid_num = ast_strdup(number);
        }
 
        if (call->remoteAliases) {
                for (alias = call->remoteAliases; alias; alias = alias->next) {
                        if (alias->type == T_H225AliasAddress_h323_ID) {
                                if (!p->callerid_name) {
-                                       p->callerid_name = strdup(alias->value);
+                                       p->callerid_name = ast_strdup(alias->value);
                                }
                                ast_copy_string(p->caller_h323id, alias->value, sizeof(p->caller_h323id));
                                }
          else if(alias->type == T_H225AliasAddress_dialedDigits)
          {
             if(!p->callerid_num)
-               p->callerid_num = strdup(alias->value);
+               p->callerid_num = ast_strdup(alias->value);
                                ast_copy_string(p->caller_dialedDigits, alias->value, 
                                                                                                                        sizeof(p->caller_dialedDigits));
          }
@@ -1874,7 +1874,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
        user = find_user(p->callerid_name, call->remoteIP);
        if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
                ast_mutex_lock(&user->lock);
-               p->username = strdup(user->name);
+               p->username = ast_strdup(user->name);
                p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
                                                  ast_strdup(user->name);
                ast_copy_string(p->context, user->context, sizeof(p->context));
@@ -1920,7 +1920,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
                ast_mutex_unlock(&user->lock);
        } else {
         if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
-               p->username = strdup(call->remoteIP);
+               p->username = ast_strdup(call->remoteIP);
                p->directrtp = gDirectRTP;
                p->earlydirect = gEarlyDirect;
        } else {
@@ -2273,7 +2273,7 @@ int onCallCleared(ooCallData *call)
                }
                ast_mutex_unlock(&userl.lock);
 
-               free(user);
+               ast_free(user);
        }  
 
        if (gH323Debug)
@@ -2305,13 +2305,13 @@ void ooh323_delete_peer(struct ooh323_peer *peer)
                        }
                ast_mutex_unlock(&peerl.lock);
 
-      if(peer->h323id)   free(peer->h323id);
-      if(peer->email)    free(peer->email);
-      if(peer->url)      free(peer->url);
-      if(peer->e164)     free(peer->e164);
+               ast_free(peer->h323id);
+               ast_free(peer->email);
+               ast_free(peer->url);
+               ast_free(peer->e164);
 
-      ao2_cleanup(peer->cap);
-               free(peer);
+               ao2_cleanup(peer->cap);
+               ast_free(peer);
        }  
 
        if (gH323Debug)
@@ -2797,8 +2797,8 @@ int reload_config(int reload)
                while (cur) {
                        prev = cur;
                        cur = cur->next;
-                       free(prev->value);
-                       free(prev);
+                       ast_free(prev->value);
+                       ast_free(prev);
                }
                gAliasList = NULL;
                ooH323EpClearAllAliases();
@@ -2913,7 +2913,7 @@ int reload_config(int reload)
                                ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
                        }
                        pNewAlias->type =  T_H225AliasAddress_h323_ID;
-                       pNewAlias->value = strdup(v->value);
+                       pNewAlias->value = ast_strdup(v->value);
                        pNewAlias->next = gAliasList;
                        gAliasList = pNewAlias;
                        pNewAlias = NULL;
@@ -2934,7 +2934,7 @@ int reload_config(int reload)
                                        return 1;
                                }
                                pNewAlias->type =  T_H225AliasAddress_dialedDigits;
-                               pNewAlias->value = strdup(v->value);
+                               pNewAlias->value = ast_strdup(v->value);
                                pNewAlias->next = gAliasList;
                                gAliasList = pNewAlias;
                                pNewAlias = NULL;
@@ -2949,7 +2949,7 @@ int reload_config(int reload)
                                return 1;
                        }
                        pNewAlias->type =  T_H225AliasAddress_email_ID;
-                       pNewAlias->value = strdup(v->value);
+                       pNewAlias->value = ast_strdup(v->value);
                        pNewAlias->next = gAliasList;
                        gAliasList = pNewAlias;
                        pNewAlias = NULL;
@@ -4094,22 +4094,22 @@ int ooh323_destroy(struct ooh323_pvt *p)
                }
 
                if (cur->username) {
-                       free(cur->username);
+                       ast_free(cur->username);
                        cur->username = 0;
                }
 
                if (cur->host) {
-                       free(cur->host);
+                       ast_free(cur->host);
                        cur->host = 0;
                }
 
                if (cur->callerid_name) {
-                       free(cur->callerid_name);
+                       ast_free(cur->callerid_name);
                        cur->callerid_name = 0;
                }
                
                if (cur->callerid_num) {
-                       free(cur->callerid_num);
+                       ast_free(cur->callerid_num);
                        cur->callerid_num = 0;
                }
 
@@ -4151,7 +4151,7 @@ int ooh323_destroy(struct ooh323_pvt *p)
                user->inUse--;
                ast_mutex_unlock(&user->lock);
          }
-         free(cur->neighbor.user);
+         ast_free(cur->neighbor.user);
         }
       } else {
 /* outgoing limit decrement here !!! */
@@ -4181,10 +4181,10 @@ int delete_peers()
                cur = cur->next;
 
                ast_mutex_destroy(&prev->lock);
-      if(prev->h323id)   free(prev->h323id);
-      if(prev->email)    free(prev->email);
-      if(prev->url)      free(prev->url);
-      if(prev->e164)     free(prev->e164);
+               ast_free(prev->h323id);
+               ast_free(prev->email);
+               ast_free(prev->url);
+               ast_free(prev->e164);
       if(prev->rtpmask) {
                ast_mutex_lock(&prev->rtpmask->lock);
                prev->rtpmask->inuse--;
@@ -4192,10 +4192,10 @@ int delete_peers()
                if (prev->rtpmask->inuse == 0) {
                        regfree(&prev->rtpmask->regex);
                        ast_mutex_destroy(&prev->rtpmask->lock);
-                       free(prev->rtpmask);
+                       ast_free(prev->rtpmask);
                }
       }
-               free(prev);
+               ast_free(prev);
 
                if (cur == peerl.peers) {
                        break;
@@ -4223,11 +4223,11 @@ int delete_users()
                        if (prev->rtpmask->inuse == 0) {
                                regfree(&prev->rtpmask->regex);
                                ast_mutex_destroy(&prev->rtpmask->lock);
-                               free(prev->rtpmask);
+                               ast_free(prev->rtpmask);
                        }
                }
        ao2_cleanup(prev->cap);
-               free(prev);
+               ast_free(prev);
                if (cur == userl.users) {
                        break;
                }
@@ -4339,8 +4339,8 @@ static int unload_module(void)
        while (cur) {
          prev = cur;
          cur = cur->next;
-         free(prev->value);
-         free(prev);
+         ast_free(prev->value);
+         ast_free(prev);
        }
        gAliasList = NULL;
 
@@ -4504,7 +4504,7 @@ static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance
                memset(&p->redirip, 0, sizeof(p->redirip));
        }
 
-       callToken = (p->callToken ? strdup(p->callToken) : NULL);
+       callToken = (p->callToken ? ast_strdup(p->callToken) : NULL);
 
        if (!callToken) {
                if (gH323Debug) {
@@ -4532,7 +4532,7 @@ static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance
        }
 
        ast_mutex_unlock(&p->lock);
-       free(callToken);
+       ast_free(callToken);
        return 0;
 
 }
index 46f1fc8..fe6c180 100644 (file)
@@ -15,6 +15,7 @@
  *****************************************************************************/
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/utils.h"
 
 #include "ooasn1.h"
 #include <stdlib.h>
@@ -157,11 +158,11 @@ int setPERBuffer (OOCTXT* pctxt,
 OOCTXT* newContext () 
 {
    /* OOCTXT* pctxt = (OOCTXT*) ASN1CRTMALLOC0 (sizeof(OOCTXT)); */
-   OOCTXT* pctxt = (OOCTXT*) malloc (sizeof(OOCTXT));
+   OOCTXT* pctxt = ast_malloc(sizeof(OOCTXT));
    if (pctxt) {
       if (initContext(pctxt) != ASN_OK) {
          /* ASN1CRTFREE0 (pctxt); */
-        free(pctxt);
+        ast_free(pctxt);
          pctxt = 0;
       }
       pctxt->flags |= ASN1DYNCTXT;
index de660c5..6aef0f4 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/utils.h"
 #include <stdlib.h>
 #include "ooasn1.h"
 
@@ -89,7 +90,7 @@ int errAddStrParm (ASN1ErrInfo* pErrInfo, const char* errprm_p)
 #if defined(_NO_THREADS) || !defined(_NO_MALLOC)
    if (pErrInfo->parmcnt < ASN_K_MAXERRP) {
       /* char* tmpstr = (char*) ASN1CRTMALLOC0 (strlen(errprm_p)+1); */
-      char* tmpstr = (char*) malloc (strlen(errprm_p)+1);
+      char* tmpstr = ast_malloc(strlen(errprm_p) + 1);
       strcpy (tmpstr, errprm_p);
       pErrInfo->parms[pErrInfo->parmcnt] = tmpstr;
       pErrInfo->parmcnt++;
@@ -118,7 +119,7 @@ void errFreeParms (ASN1ErrInfo* pErrInfo)
 
    for (i = 0; i < pErrInfo->parmcnt; i++)
       /* ASN1CRTFREE0 ((char*)pErrInfo->parms[i]); */
-      free ((char*)pErrInfo->parms[i]);
+      ast_free((char*)pErrInfo->parms[i]);
 #endif
 
    pErrInfo->parmcnt = 0;
index c7aed04..99a5308 100644 (file)
@@ -15,6 +15,7 @@
  *****************************************************************************/
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/utils.h"
 #include <stdlib.h>
 #include "memheap.h"
 
@@ -176,13 +177,13 @@ void* memHeapAlloc (void** ppvMemHeap, int nbytes)
 
       /* allocate raw block */
 
-      data = malloc (nbytes);
+      data = ast_malloc(nbytes);
       if (data == NULL) {
          return NULL;
       }
       pMemLink = memHeapAddBlock (ppMemLink, data, RTMEMMALLOC | RTMEMRAW);
       if (pMemLink == 0) {
-         free (data);
+         ast_free(data);
          return NULL;
       }
       /* save size of the RAW memory block behind the pMemLink */
@@ -333,7 +334,7 @@ void* memHeapAlloc (void** ppvMemHeap, int nbytes)
             ((((ASN1UINT)dataUnits) * 8u) + sizeof (OSMemBlk));
       }  
 
-      pmem = (ASN1OCTET*) malloc (allocSize + sizeof (OSMemLink));
+      pmem = (ASN1OCTET*) ast_malloc(allocSize + sizeof (OSMemLink));
       if (0 != pmem) {
          OSMemElemDescr* pElem;
 
@@ -357,7 +358,7 @@ void* memHeapAlloc (void** ppvMemHeap, int nbytes)
 
          if (memHeapAddBlock (ppMemLink, pMemBlk, RTMEMSTD | RTMEMLINK) == 0) 
          {
-            free (pmem);
+            ast_free(pmem);
            ast_mutex_unlock(&pMemHeap->pLock);
             return NULL;
          }
@@ -437,12 +438,12 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
          if ((pMemLink->blockType & RTMEMLINK) && 
              (pMemLink->blockType & RTMEMMALLOC))
          {
-            free (pMemLink);
+            ast_free(pMemLink);
          }
          else {
             if (pMemLink->blockType & RTMEMMALLOC)
-               free (pMemLink->pMemBlk);
-            free (pMemLink);
+               ast_free(pMemLink->pMemBlk);
+            ast_free(pMemLink);
          }
         ast_mutex_unlock(&pMemHeap->pLock);
          return;
@@ -553,11 +554,11 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
             FILLFREEMEM (pMemBlk->plink, sizeof (*pMemBlk->plink));
             FILLFREEMEM (pMemBlk->data, (pMemBlk->nunits * 8u));
          
-            free (pMemBlk->plink);
+            ast_free(pMemBlk->plink);
             
             if (!(blockType & RTMEMLINK)) {
                FILLFREEMEM (pMemBlk, sizeof (*pMemBlk));
-               free (pMemBlk);
+               ast_free(pMemBlk);
             }
             RTMEMDIAG2 ("memHeapFreePtr: pMemBlk = 0x%x was freed\n", 
                              pMemBlk);
@@ -748,7 +749,7 @@ void* memHeapRealloc (void** ppvMemHeap, void* mem_p, int nbytes_)
            pMemLink->pMemBlk == mem_p) 
       {
          if (pMemLink->blockType & RTMEMMALLOC) {
-             void *newMemBlk = realloc (pMemLink->pMemBlk, nbytes_);
+             void *newMemBlk = ast_realloc(pMemLink->pMemBlk, nbytes_);
              if (newMemBlk == 0) 
                 return 0;
              pMemLink->pMemBlk = newMemBlk;
@@ -1038,8 +1039,8 @@ void memHeapFreeAll (void** ppvMemHeap)
          if (((pMemLink2->blockType & RTMEMSTD) || 
               (pMemLink2->blockType & RTMEMMALLOC)) &&
               !(pMemLink2->blockType & RTMEMLINK)) 
-            free (pMemLink2->pMemBlk);
-         free (pMemLink2);
+            ast_free(pMemLink2->pMemBlk);
+         ast_free(pMemLink2);
       }
    }
    ast_mutex_unlock(&pMemHeap->pLock);
@@ -1075,12 +1076,12 @@ void memHeapRelease (void** ppvMemHeap)
          pMemLink2 = pMemLink;
          pMemLink  = pMemLink2->pnext;
 
-         free (pMemLink2);
+         ast_free(pMemLink2);
       }
 
       if ((*ppMemHeap)->flags & RT_MH_FREEHEAPDESC) {
          ast_mutex_destroy(&pMemHeap->pLock);
-         free (*ppMemHeap);
+         ast_free(*ppMemHeap);
       }
       *ppMemHeap = 0;
    }
@@ -1215,8 +1216,7 @@ static OSMemLink* memHeapAddBlock (OSMemLink** ppMemLink,
    if (blockType & RTMEMLINK) 
       pMemLink = (OSMemLink*) (((ASN1OCTET*)pMemBlk) - sizeof (OSMemLink));
    else {
-      pMemLink = (OSMemLink*) malloc (
-         sizeof(OSMemLink) + sizeof (int));
+      pMemLink = ast_malloc(sizeof(OSMemLink) + sizeof(int));
       if (pMemLink == 0) return 0;
       /* An extra integer is necessary to save a size of a RAW memory block
          to perform rtMemRealloc through malloc/memcpy/free */
@@ -1339,7 +1339,7 @@ int memHeapCreate (void** ppvMemHeap)
    OSMemHeap* pMemHeap;
    if (ppvMemHeap == 0) return ASN_E_INVPARAM;
 
-   pMemHeap = (OSMemHeap*) malloc (sizeof (OSMemHeap));
+   pMemHeap = ast_malloc(sizeof (OSMemHeap));
    if (pMemHeap == NULL) return ASN_E_NOMEM;
    memset (pMemHeap, 0, sizeof (OSMemHeap));
    pMemHeap->defBlkSize = g_defBlkSize;
index 70677ab..2eefb46 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/utils.h"
 
 #include "ootrace.h"
 #include "ootypes.h"
@@ -366,13 +367,13 @@ int ooCleanCall(OOH323CallData *call)
        if ((call->rtpMask->inuse) == 0) {
                regfree(&call->rtpMask->regex);
                ast_mutex_destroy(&call->rtpMask->lock);
-               free(call->rtpMask);
+               ast_free(call->rtpMask);
        }
    }
 
    if ((pctxt = call->msgctxt) != NULL) {
        freeContext(pctxt);
-       free(pctxt);
+       ast_free(pctxt);
        call->msgctxt = NULL;
    }
 /* May !!!! Fix it !! */
index 50a75c2..353818d 100644 (file)
@@ -57,13 +57,13 @@ int ooCreateCallCmdConnection(OOH323CallData* call)
 
     OOTRACEINFO2("INFO: create cmd connect for call: %lx\n", call);
 
-   call->CmdChanLock = calloc(1, sizeof(ast_mutex_t));
+   call->CmdChanLock = ast_calloc(1, sizeof(ast_mutex_t));
    ast_mutex_init(call->CmdChanLock);
 
 
    if ((ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, thePipe)) == -1) {
       ast_mutex_destroy(call->CmdChanLock);
-      free(call->CmdChanLock);
+      ast_free(call->CmdChanLock);
       call->CmdChanLock = NULL;
       return OO_FAILED;
    }
@@ -94,7 +94,7 @@ int ooCloseCallCmdConnection(OOH323CallData* call)
    call->CmdChan = 0;
    ast_mutex_unlock(call->CmdChanLock);
    ast_mutex_destroy(call->CmdChanLock);
-   free(call->CmdChanLock);
+   ast_free(call->CmdChanLock);
    call->CmdChanLock = NULL;
 
    return OO_OK;
@@ -267,9 +267,9 @@ int ooReadAndProcessStackCommand()
             default: OOTRACEERR1("ERROR:Unknown command\n");
          }
       }
-      if(cmd.param1) free(cmd.param1);
-      if(cmd.param2) free(cmd.param2);
-      if(cmd.param3) free(cmd.param3);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
+      ast_free(cmd.param3);
    }
 
 
@@ -302,7 +302,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
       bPoint +=  sizeof(OOStackCommand);
 
       if (cmd.plen1 > 0) {
-       cmd.param1 = malloc(cmd.plen1 + 1);
+       cmd.param1 = ast_malloc(cmd.plen1 + 1);
        if (!cmd.param1) 
                return OO_FAILED;
        memset(cmd.param1, 0, cmd.plen1 + 1);
@@ -311,7 +311,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
       }
 
       if (cmd.plen2 > 0) {
-       cmd.param2 = malloc(cmd.plen2 + 1);
+       cmd.param2 = ast_malloc(cmd.plen2 + 1);
        if (!cmd.param2) 
                return OO_FAILED;
        memset(cmd.param2, 0, cmd.plen2 + 1);
@@ -320,7 +320,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
       }
 
       if (cmd.plen3 > 0) {
-       cmd.param3 = malloc(cmd.plen3 + 1);
+       cmd.param3 = ast_malloc(cmd.plen3 + 1);
        if (!cmd.param3) 
                return OO_FAILED;
        memset(cmd.param3, 0, cmd.plen3 + 1);
index f2c26a5..771b3c6 100644 (file)
@@ -79,7 +79,7 @@ OOStkCmdStat ooMakeCall
 
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_MAKECALL;
-   cmd.param1 = (void*) malloc(strlen(dest)+1);
+   cmd.param1 = ast_malloc(strlen(dest)+1);
    if(!cmd.param1)
    {
       return OO_STKCMD_MEMERR;
@@ -87,10 +87,10 @@ OOStkCmdStat ooMakeCall
    strcpy((char*)cmd.param1, dest);
 
   
-   cmd.param2 = (void*) malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(strlen(callToken)+1);
    if(!cmd.param2)
    {
-      free(cmd.param1);
+      ast_free(cmd.param1);
       return OO_STKCMD_MEMERR;
    }
    
@@ -101,11 +101,11 @@ OOStkCmdStat ooMakeCall
       cmd.param3 = 0;
    }
    else {
-      cmd.param3 = (void*) malloc(sizeof(ooCallOptions));
+      cmd.param3 = ast_malloc(sizeof(ooCallOptions));
       if(!cmd.param3)
       {
-         free(cmd.param1);
-         free(cmd.param2);
+         ast_free(cmd.param1);
+         ast_free(cmd.param2);
          return OO_STKCMD_MEMERR;
       }
       memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions));
@@ -113,9 +113,9 @@ OOStkCmdStat ooMakeCall
 
    if(ooWriteStackCommand(&cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
-      if(cmd.param3) free(cmd.param3);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
+      if(cmd.param3) ast_free(cmd.param3);
       return OO_STKCMD_WRITEERR;
    }
 
@@ -149,7 +149,7 @@ OOStkCmdStat ooRunCall
 
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_MAKECALL;
-   cmd.param1 = (void*) malloc(strlen(dest)+1);
+   cmd.param1 = ast_malloc(strlen(dest)+1);
    if(!cmd.param1)
    {
       return OO_STKCMD_MEMERR;
@@ -158,10 +158,10 @@ OOStkCmdStat ooRunCall
    cmd.plen1 = strlen(dest);
 
   
-   cmd.param2 = (void*) malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(strlen(callToken)+1);
    if(!cmd.param2)
    {
-      free(cmd.param1);
+      ast_free(cmd.param1);
       return OO_STKCMD_MEMERR;
    }
    
@@ -173,11 +173,11 @@ OOStkCmdStat ooRunCall
       cmd.param3 = 0;
    }
    else {
-      cmd.param3 = (void*) malloc(sizeof(ooCallOptions));
+      cmd.param3 = ast_malloc(sizeof(ooCallOptions));
       if(!cmd.param3)
       {
-         free(cmd.param1);
-         free(cmd.param2);
+         ast_free(cmd.param1);
+         ast_free(cmd.param2);
          return OO_STKCMD_MEMERR;
       }
       memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions));
@@ -186,16 +186,16 @@ OOStkCmdStat ooRunCall
 
    if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
-      if(cmd.param3) free(cmd.param3);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
+      if(cmd.param3) ast_free(cmd.param3);
       return OO_STKCMD_WRITEERR;
    }
 
 
-   free(cmd.param1);
-   free(cmd.param2);
-   if(cmd.param3) free(cmd.param3);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
+   if(cmd.param3) ast_free(cmd.param3);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -223,7 +223,7 @@ OOStkCmdStat ooManualRingback(const char *callToken)
 
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_MANUALRINGBACK;
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
    if(!cmd.param1)
    {
       return OO_STKCMD_MEMERR;
@@ -233,11 +233,11 @@ OOStkCmdStat ooManualRingback(const char *callToken)
    
    if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
    {
-      free(cmd.param1);
+      ast_free(cmd.param1);
       return OO_STKCMD_WRITEERR;
    }
 
-   free(cmd.param1);
+   ast_free(cmd.param1);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -267,7 +267,7 @@ OOStkCmdStat ooManualProgress(const char *callToken)
 
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_MANUALPROGRESS;
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
    if(!cmd.param1)
    {
       return OO_STKCMD_MEMERR;
@@ -277,11 +277,11 @@ OOStkCmdStat ooManualProgress(const char *callToken)
    
    if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
    {
-      free(cmd.param1);
+      ast_free(cmd.param1);
       return OO_STKCMD_WRITEERR;
    }
 
-   free(cmd.param1);
+   ast_free(cmd.param1);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -309,7 +309,7 @@ OOStkCmdStat ooAnswerCall(const char *callToken)
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_ANSCALL;
 
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
    if(!cmd.param1)
    {
       return OO_STKCMD_MEMERR;
@@ -319,11 +319,11 @@ OOStkCmdStat ooAnswerCall(const char *callToken)
 
    if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
    {
-      free(cmd.param1);
+      ast_free(cmd.param1);
       return OO_STKCMD_WRITEERR;
    }
 
-   free(cmd.param1);
+   ast_free(cmd.param1);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -350,12 +350,12 @@ OOStkCmdStat ooForwardCall(const char* callToken, char *dest)
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_FWDCALL;
 
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
-   cmd.param2 = (void*) malloc(strlen(dest)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(strlen(dest)+1);
    if(!cmd.param1 || !cmd.param2)
    {
-      if(cmd.param1)   free(cmd.param1);  /* Release memory */
-      if(cmd.param2)   free(cmd.param2);
+      if(cmd.param1)   ast_free(cmd.param1);  /* Release memory */
+      if(cmd.param2)   ast_free(cmd.param2);
       return OO_STKCMD_MEMERR;
    }
    strcpy((char*)cmd.param1, callToken);
@@ -365,12 +365,12 @@ OOStkCmdStat ooForwardCall(const char* callToken, char *dest)
 
    if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
       return OO_STKCMD_WRITEERR;
    }
-   free(cmd.param1);
-   free(cmd.param2);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -399,14 +399,14 @@ OOStkCmdStat ooHangCall(const char* callToken, OOCallClearReason reason, int q93
 
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_HANGCALL;
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
-   cmd.param2 = (void*) malloc(sizeof(OOCallClearReason));
-   cmd.param3 = (void*) malloc(sizeof(int));
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(sizeof(OOCallClearReason));
+   cmd.param3 = ast_malloc(sizeof(int));
    if(!cmd.param1 || !cmd.param2 || !cmd.param3)
    {
-      if(cmd.param1)   free(cmd.param1); /* Release memory */
-      if(cmd.param2)   free(cmd.param2);
-      if(cmd.param3)   free(cmd.param3);
+      if(cmd.param1)   ast_free(cmd.param1); /* Release memory */
+      if(cmd.param2)   ast_free(cmd.param2);
+      if(cmd.param3)   ast_free(cmd.param3);
       return OO_STKCMD_MEMERR;
    }
    strcpy((char*)cmd.param1, callToken);
@@ -418,14 +418,14 @@ OOStkCmdStat ooHangCall(const char* callToken, OOCallClearReason reason, int q93
 
    if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
-      free(cmd.param3);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
+      ast_free(cmd.param3);
       return OO_STKCMD_WRITEERR;
    }
-   free(cmd.param1);
-   free(cmd.param2);
-   free(cmd.param3);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
+   ast_free(cmd.param3);
    
    return OO_STKCMD_SUCCESS;
 }
@@ -473,12 +473,12 @@ OOStkCmdStat ooSendDTMFDigit(const char *callToken, const char* dtmf)
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_SENDDIGIT;
 
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
-   cmd.param2 = (void*) malloc(strlen(dtmf)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(strlen(dtmf)+1);
    if(!cmd.param1 || !cmd.param2)
    {
-      if(cmd.param1)   free(cmd.param1); /* Release memory */
-      if(cmd.param2)   free(cmd.param2);
+      if(cmd.param1)   ast_free(cmd.param1); /* Release memory */
+      if(cmd.param2)   ast_free(cmd.param2);
       return OO_STKCMD_MEMERR;
    }
    strcpy((char*)cmd.param1, callToken);
@@ -488,12 +488,12 @@ OOStkCmdStat ooSendDTMFDigit(const char *callToken, const char* dtmf)
    
    if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
       return OO_STKCMD_WRITEERR;
    }
-   free(cmd.param1);
-   free(cmd.param2);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -521,12 +521,12 @@ OOStkCmdStat ooSetANI(const char *callToken, const char* ani)
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_SETANI;
 
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
-   cmd.param2 = (void*) malloc(strlen(ani)+1);
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(strlen(ani)+1);
    if(!cmd.param1 || !cmd.param2)
    {
-      if(cmd.param1)   free(cmd.param1); /* Release memory */
-      if(cmd.param2)   free(cmd.param2);
+      if(cmd.param1)   ast_free(cmd.param1); /* Release memory */
+      if(cmd.param2)   ast_free(cmd.param2);
       return OO_STKCMD_MEMERR;
    }
    strcpy((char*)cmd.param1, callToken);
@@ -536,12 +536,12 @@ OOStkCmdStat ooSetANI(const char *callToken, const char* ani)
    
    if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
       return OO_STKCMD_WRITEERR;
    }
-   free(cmd.param1);
-   free(cmd.param2);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
 
    return OO_STKCMD_SUCCESS;
 }
@@ -631,12 +631,12 @@ OOStkCmdStat ooRequestChangeMode(const char *callToken, int isT38Mode)
    memset(&cmd, 0, sizeof(OOStackCommand));
    cmd.type = OO_CMD_REQMODE;
 
-   cmd.param1 = (void*) malloc(strlen(callToken)+1);
-   cmd.param2 = (void*) malloc(sizeof(int));
+   cmd.param1 = ast_malloc(strlen(callToken)+1);
+   cmd.param2 = ast_malloc(sizeof(int));
    if(!cmd.param1 || !cmd.param2)
    {
-      if(cmd.param1)   free(cmd.param1); /* Release memory */
-      if(cmd.param2)   free(cmd.param2);
+      ast_free(cmd.param1); /* Release memory */
+      ast_free(cmd.param2);
       return OO_STKCMD_MEMERR;
    }
    strcpy((char*)cmd.param1, callToken);
@@ -646,12 +646,12 @@ OOStkCmdStat ooRequestChangeMode(const char *callToken, int isT38Mode)
    
    if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
    {
-      free(cmd.param1);
-      free(cmd.param2);
+      ast_free(cmd.param1);
+      ast_free(cmd.param2);
       return OO_STKCMD_WRITEERR;
    }
-   free(cmd.param1);
-   free(cmd.param2);
+   ast_free(cmd.param1);
+   ast_free(cmd.param2);
 
    return OO_STKCMD_SUCCESS;
 }
index ddc6bf6..76f8422 100644 (file)
@@ -961,7 +961,7 @@ int ooMonitorCallChannels(OOH323CallData *call)
    ast_cond_destroy(&call->gkWait);
    pctxt = call->pctxt;
    freeContext(pctxt);
-   free(pctxt);
+   ast_free(pctxt);
 
    return OO_OK;
 }
index 3986a86..a2a443c 100644 (file)
@@ -19,6 +19,7 @@
 */
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/utils.h"
 
 #include <stdlib.h>
 /* #ifdef HAVE_MALLOC_H
@@ -126,10 +127,10 @@ void printBitStrValue (ASN1UINT numbits, const ASN1OCTET* data)
    indent ();
    OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8));
 #else
-   char* s = (char*)malloc(numbits + 8);
+   char* s = ast_malloc(numbits + 8);
    indent ();
    OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8));
-   free(s);
+   ast_free(s);
 #endif
 }
 
@@ -141,10 +142,10 @@ void printOctStrValue (ASN1UINT numocts, const ASN1OCTET* data)
    indent ();
    OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz));
 #else
-   char* s = (char*)malloc(bufsiz);
+   char* s = ast_malloc(bufsiz);
    indent ();
    OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz));
-   free(s);
+   ast_free(s);
 #endif
 }
 
index bceb077..3096d1e 100644 (file)
@@ -121,7 +121,7 @@ void* ooh323c_call_thread(void* dummy)
 
  close(mycthread->thePipe[0]);
  close(mycthread->thePipe[1]);
- free(mycthread);
+ ast_free(mycthread);
  ast_module_unref(myself);
  ast_update_use_count();
  return NULL;
@@ -155,7 +155,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
        ast_module_ref(myself);
        if ((socketpair(PF_LOCAL, SOCK_STREAM, 0, cur->thePipe)) == -1) {
                ast_log(LOG_ERROR, "Can't create thread pipe for call %s\n", call->callToken);
-               free(cur);
+               ast_free(cur);
                return -1;
        }
        cur->inUse = TRUE;
@@ -173,7 +173,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
                ast_mutex_destroy(&cur->lock);
                close(cur->thePipe[0]);
                close(cur->thePipe[1]);
-               free(cur);
+               ast_free(cur);
                return -1;
        }
 
index 8d40431..a4e4726 100644 (file)
@@ -497,7 +497,7 @@ static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
                                jack_port_name(jack_data->output_port));
                }
 
-               free((void *) ports);
+               jack_free(ports);
 
                break;
        }
@@ -528,7 +528,7 @@ static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
                                jack_port_name(jack_data->input_port));
                }
 
-               free((void *) ports);
+               jack_free(ports);
 
                break;
        }
index 230dcd0..9647fcd 100644 (file)
@@ -3232,7 +3232,7 @@ static void destroy_queue(void *obj)
        ast_string_field_free_memory(q);
        for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
                if (q->sound_periodicannounce[i]) {
-                       free(q->sound_periodicannounce[i]);
+                       ast_free(q->sound_periodicannounce[i]);
                }
        }
        ao2_ref(q->members, -1);
index fa3eade..a66115b 100644 (file)
@@ -240,21 +240,21 @@ retry:
 done:
        ast_mutex_unlock(&tds_lock);
 
-       free(accountcode_ai);
-       free(clidnum_ai);
-       free(clid_ai);
-       free(cidani_ai);
-       free(cidrdnis_ai);
-       free(ciddnid_ai);
-       free(exten_ai);
-       free(context_ai);
-       free(channel_ai);
-       free(app_ai);
-       free(appdata_ai);
-       free(uniqueid_ai);
-       free(linkedid_ai);
-       free(userfield_ai);
-       free(peer_ai);
+       ast_free(accountcode_ai);
+       ast_free(clidnum_ai);
+       ast_free(clid_ai);
+       ast_free(cidani_ai);
+       ast_free(cidrdnis_ai);
+       ast_free(ciddnid_ai);
+       ast_free(exten_ai);
+       ast_free(context_ai);
+       ast_free(channel_ai);
+       ast_free(app_ai);
+       ast_free(appdata_ai);
+       ast_free(uniqueid_ai);
+       ast_free(linkedid_ai);
+       ast_free(userfield_ai);
+       ast_free(peer_ai);
 
        return;
 }
@@ -317,11 +317,11 @@ static int execute_and_consume(DBPROCESS *dbproc, const char *fmt, ...)
        va_end(ap);
 
        if (dbfcmd(dbproc, buffer) == FAIL) {
-               free(buffer);
+               ast_free(buffer);
                return 1;
        }
 
-       free(buffer);
+       ast_free(buffer);
 
        if (dbsqlexec(dbproc) == FAIL) {
                return 1;
index c34a6c4..7ddbcf0 100644 (file)
@@ -860,7 +860,7 @@ static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_a
        } else
                ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
 
-       free(s);
+       ast_free(s);
 
        unref_pvt(pvt);
 
index c72df66..0f6b916 100644 (file)
@@ -3812,7 +3812,7 @@ static int mgcp_prune_realtime_gateway(struct mgcp_gateway *g)
                        if (prune) {
                                ast_mutex_destroy(&s->lock);
                                ast_mutex_destroy(&s->cx_queue_lock);
-                               free(s);
+                               ast_free(s);
                        }
                }
                ast_mutex_unlock(&e->lock);
@@ -3822,7 +3822,7 @@ static int mgcp_prune_realtime_gateway(struct mgcp_gateway *g)
                        ast_mutex_destroy(&e->lock);
                        ast_mutex_destroy(&e->rqnt_queue_lock);
                        ast_mutex_destroy(&e->cmd_queue_lock);
-                       free(e);
+                       ast_free(e);
                }
        }
        if (prune) {
@@ -3914,7 +3914,7 @@ static void *do_monitor(void *data)
                                                }
                                                ast_mutex_unlock(&g->msgs_lock);
                                                ast_mutex_destroy(&g->msgs_lock);
-                                               free(g);
+                                               ast_free(g);
                                        } else {
                                                ast_mutex_unlock(&g->msgs_lock);
                                                gprev = g;
index a04a63b..1cfb3a7 100644 (file)
@@ -8540,16 +8540,16 @@ static void delete_devices(void)
                }
                /* Delete all speeddials for this device */
                while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {
-                       free(sd->container);
-                       free(sd);
+                       ast_free(sd->container);
+                       ast_free(sd);
                }
                /* Delete all serviceurls for this device */
                while ((surl = AST_LIST_REMOVE_HEAD(&d->serviceurls, list))) {
-                       free(surl);
+                       ast_free(surl);
                }
                /* Delete all addons for this device */
                while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) {
-                       free(a);
+                       ast_free(a);
                }
                d = skinny_device_destroy(d);
        }
@@ -8603,11 +8603,11 @@ int skinny_reload(void)
                }
                /* Delete all speeddials for this device */
                while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {
-                       free(sd);
+                       ast_free(sd);
                }
                /* Delete all addons for this device */
                while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) {
-                       free(a);
+                       ast_free(a);
                }
                AST_LIST_REMOVE_CURRENT(list);
                d = skinny_device_destroy(d);
index 5c4e76a..e1ee13b 100755 (executable)
@@ -6,9 +6,19 @@ if [ -f addons/mp3/mpg123.h ]; then
     echo "need to be downloaded."
     echo "***"
 
+    # Manually patch interface.c if not done yet.
+    if ! grep -q WRAP_LIBC_MALLOC addons/mp3/interface.c; then
+        sed -i -e '/#include "asterisk.h"/i#define WRAP_LIBC_MALLOC' \
+            addons/mp3/interface.c
+    fi
+
     exit 1
 fi
 
 svn export http://svn.digium.com/svn/thirdparty/mp3/trunk addons/mp3 $@
 
+# Manually patch interface.c.
+sed -i -e '/#include "asterisk.h"/i#define WRAP_LIBC_MALLOC' \
+    addons/mp3/interface.c
+
 exit 0
index 22ee582..6c96f8e 100644 (file)
@@ -195,7 +195,7 @@ static void curlds_free(void *data)
                return;
        }
        while ((setting = AST_LIST_REMOVE_HEAD(list, list))) {
-               free(setting);
+               ast_free(setting);
        }
        AST_LIST_HEAD_DESTROY(list);
 }
@@ -393,7 +393,7 @@ yuck:
        AST_LIST_TRAVERSE_SAFE_BEGIN(list, cur, list) {
                if (cur->key == new->key) {
                        AST_LIST_REMOVE_CURRENT(list);
-                       free(cur);
+                       ast_free(cur);
                        break;
                }
        }
index 1b00812..6086509 100644 (file)
@@ -74,10 +74,45 @@ int __ast_vasprintf(char **strp, const char *format, va_list ap, const char *fil
 void __ast_mm_init_phase_1(void);
 void __ast_mm_init_phase_2(void);
 
+/* Redefine libc malloc to our own versions */
 
-/* Provide our own definitions */
+#ifdef WRAP_LIBC_MALLOC
 #define calloc(a,b) \
        __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define malloc(a) \
+       __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define free(a) \
+       __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define realloc(a,b) \
+       __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define strdup(a) \
+       __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define strndup(a,b) \
+       __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define asprintf(a, b, c...) \
+       __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
+#define vasprintf(a,b,c) \
+       __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+#else
+#define calloc(a,b) \
+       Do_not_use_calloc__use_ast_calloc(a,b)
+#define malloc(a) \
+       Do_not_use_malloc__use_ast_malloc(a)
+#define free(a) \
+       Do_not_use_free__use_ast_free_or_ast_std_free_for_remotely_allocated_memory(a)
+#define realloc(a,b) \
+       Do_not_use_realloc__use_ast_realloc(a,b)
+#define strdup(a) \
+       Do_not_use_strdup__use_ast_strdup(a)
+#define strndup(a,b) \
+       Do_not_use_strndup__use_ast_strndup(a,b)
+#define asprintf(a, b, c...) \
+       Do_not_use_asprintf__use_ast_asprintf(a,b,c)
+#define vasprintf(a,b,c) \
+       Do_not_use_vasprintf__use_ast_vasprintf(a,b,c)
+#endif
+
+/* Provide our own definitions */
 
 #define ast_calloc(a,b) \
        __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
@@ -85,45 +120,24 @@ void __ast_mm_init_phase_2(void);
 #define ast_calloc_cache(a,b) \
        __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define malloc(a) \
-       __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_malloc(a) \
        __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define free(a) \
-       __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_free(a) \
        __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define realloc(a,b) \
-       __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_realloc(a,b) \
        __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define strdup(a) \
-       __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_strdup(a) \
        __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define strndup(a,b) \
-       __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_strndup(a,b) \
        __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
-#define asprintf(a, b, c...) \
-       __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
-
 #define ast_asprintf(a, b, c...) \
        __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
 
-#define vasprintf(a,b,c) \
-       __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
 #define ast_vasprintf(a,b,c) \
        __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
 
index e4c3c76..c0e0429 100644 (file)
@@ -857,7 +857,7 @@ void ast_jb_conf_default(struct ast_jb_conf *conf)
 }
 
 static void datastore_destroy_cb(void *data) {
-       ast_free(data);
+       free(data);
        ast_debug(1, "JITTERBUFFER datastore destroyed\n");
 }
 
index 5c3b633..a9f6c46 100644 (file)
@@ -174,7 +174,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
                }
 
                bufsz = ifn.lifn_count * sizeof(struct lifreq);
-               if (!(buf = malloc(bufsz))) {
+               if (!(buf = ast_malloc(bufsz))) {
                        close(s);
                        return -1;
                }
@@ -187,7 +187,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
                ifc.lifc_flags = 0;
                if (ioctl(s, SIOCGLIFCONF, &ifc) < 0) {
                        close(s);
-                       free(buf);
+                       ast_free(buf);
                        return -1;
                }
 
@@ -201,7 +201,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
                        }
                }
 
-               free(buf);
+               ast_free(buf);
 #endif /* SOLARIS */
 
                close(s);
index a6c7514..fd19bee 100644 (file)
@@ -1892,7 +1892,7 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) {
                if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
                        AST_RWLIST_REMOVE_CURRENT(group_list);
-                       free(gi);
+                       ast_free(gi);
                        break;
                }
        }
@@ -1900,7 +1900,7 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
 
        if (ast_strlen_zero(group)) {
                /* Enable unsetting the group */
-       } else if ((gi = calloc(1, len))) {
+       } else if ((gi = ast_calloc(1, len))) {
                gi->chan = chan;
                gi->group = (char *) gi + sizeof(*gi);
                strcpy(gi->group, group);
@@ -2176,9 +2176,9 @@ static void path_lock_destroy(struct path_lock *obj)
                close(obj->fd);
        }
        if (obj->path) {
-               free(obj->path);
+               ast_free(obj->path);
        }
-       free(obj);
+       ast_free(obj);
 }
 
 static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
@@ -2222,7 +2222,7 @@ static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
                return AST_LOCK_FAILURE;
        }
        pl->fd = fd;
-       pl->path = strdup(path);
+       pl->path = ast_strdup(path);
 
        time(&start);
        while (
index 798e3d3..f42604e 100644 (file)
@@ -91,6 +91,7 @@
  * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
  */
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 #include <sys/types.h>
index 83d3eff..e8c68e3 100644 (file)
@@ -12,6 +12,7 @@
  * $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $
  */
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 #include <sys/types.h>
index 1f67d46..51af56b 100644 (file)
@@ -1,3 +1,4 @@
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 #line 2 "ast_expr2f.c"
index 305ab23..3714643 100644 (file)
@@ -236,7 +236,7 @@ int ast_autoservice_start(struct ast_channel *chan)
                        /* There will only be a single member in the list at this point,
                           the one we just added. */
                        AST_LIST_REMOVE(&aslist, as, list);
-                       free(as);
+                       ast_free(as);
                        asthread = AST_PTHREADT_NULL;
                        res = -1;
                } else {
@@ -313,7 +313,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
        }
        ast_channel_unlock(chan);
 
-       free(as);
+       ast_free(as);
 
        return res;
 }
index 1d3755a..4221b08 100644 (file)
@@ -412,17 +412,12 @@ static void filestream_destructor(void *arg)
                }
        }
 
-       if (f->filename)
-               free(f->filename);
-       if (f->realfilename)
-               free(f->realfilename);
+       ast_free(f->filename);
+       ast_free(f->realfilename);
        if (f->vfs)
                ast_closestream(f->vfs);
-       if (f->write_buffer) {
-               ast_free(f->write_buffer);
-       }
-       if (f->orig_chan_name)
-               free((void *) f->orig_chan_name);
+       ast_free(f->write_buffer);
+       ast_free((void *)f->orig_chan_name);
        ao2_cleanup(f->lastwriteformat);
        ao2_cleanup(f->fr.subclass.format);
        ast_module_unref(f->fmt->module);
index d6cd7aa..4f52ec5 100644 (file)
@@ -26,6 +26,7 @@
        <support_level>core</support_level>
  ***/
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -255,7 +256,7 @@ ast_hashtab_create
 #else
        if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) {
 #endif
-               free(ht);
+               ast_free(ht);
                return NULL;
        }
 
index ac17ddc..def8bba 100644 (file)
@@ -610,7 +610,7 @@ void ast_module_shutdown(void)
                                mod->info->unload();
                        }
                        AST_LIST_HEAD_DESTROY(&mod->users);
-                       free(mod);
+                       ast_free(mod);
                        somethingchanged = 1;
                }
                AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
index a590e3b..eee3f0e 100644 (file)
@@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/ulaw.h"
 #include "asterisk/tdd.h"
 #include "asterisk/fskmodem.h"
+#include "asterisk/utils.h"
 #include "ecdisa.h"
 
 struct tdd_state {
@@ -104,7 +105,7 @@ void tdd_init(void)
 struct tdd_state *tdd_new(void)
 {
        struct tdd_state *tdd;
-       tdd = calloc(1, sizeof(*tdd));
+       tdd = ast_calloc(1, sizeof(*tdd));
        if (tdd) {
 #ifdef INTEGER_CALLERID
                tdd->fskd.ispb = 176;        /* 45.5 baud */
@@ -166,7 +167,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
        int b = 'X';
        int res;
        int c,x;
-       short *buf = calloc(1, 2 * len + tdd->oldlen);
+       short *buf = ast_calloc(1, 2 * len + tdd->oldlen);
        short *obuf = buf;
        if (!buf) {
                ast_log(LOG_WARNING, "Out of memory\n");
@@ -182,13 +183,13 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
                res = fsk_serial(&tdd->fskd, buf, &mylen, &b);
                if (mylen < 0) {
                        ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
-                       free(obuf);
+                       ast_free(obuf);
                        return -1;
                }
                buf += (olen - mylen);
                if (res < 0) {
                        ast_log(LOG_NOTICE, "fsk_serial failed\n");
-                       free(obuf);
+                       ast_free(obuf);
                        return -1;
                }
                if (res == 1) {
@@ -206,7 +207,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
                tdd->oldlen = mylen * 2;
        } else
                tdd->oldlen = 0;
-       free(obuf);
+       ast_free(obuf);
        if (res) {
                tdd->mode = 2;
 /* put it in mode where it
@@ -218,7 +219,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
 
 void tdd_free(struct tdd_state *tdd)
 {
-       free(tdd);
+       ast_free(tdd);
 }
 
 static inline float tdd_getcarrier(float *cr, float *ci, int bit)
index 01550c0..e76f6e8 100644 (file)
@@ -260,7 +260,7 @@ static int split_ec(const char *src, char **ext, char ** const ctx, char ** cons
                *c++ = '\0';
                *ctx = c;
                if (strchr(c, '@')) { /* two @, not allowed */
-                       free(e);
+                       ast_free(e);
                        return -1;
                }
        }
@@ -311,7 +311,7 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
                                        already_served = lookup_ci(nc, i_name);
 
                                if (!already_served && ++which > a->n)
-                                       res = strdup(i_name);
+                                       res = ast_strdup(i_name);
                        }
                        ast_unlock_context(c);
                }
@@ -328,7 +328,7 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
 
                if (a->n > 0)
                        return NULL;
-               context = dupline = strdup(s);
+               context = dupline = ast_strdup(s);
                if (!dupline) {
                        ast_log(LOG_ERROR, "Out of free memory\n");
                        return NULL;
@@ -337,18 +337,18 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
 
                if (ast_rdlock_contexts()) {
                        ast_log(LOG_ERROR, "Failed to lock contexts list\n");
-                       free(context);
+                       ast_free(context);
                        return NULL;
                }
 
                /* go through all contexts and check if is included ... */
                while (!res && (c = ast_walk_contexts(c)))
                        if (lookup_ci(c, context)) /* context is really included, complete "from" command */
-                               res = strdup("from");
+                               res = ast_strdup("from");
                ast_unlock_contexts();
                if (!res)
                        ast_log(LOG_WARNING, "%s not included anywhere\n", context);
-               free(context);
+               ast_free(context);
                return res;
        } else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */
                /*
@@ -356,7 +356,7 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
                 */
                char *context, *dupline, *from;
                const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
-               context = dupline = strdup(s);
+               context = dupline = ast_strdup(s);
                if (!dupline) {
                        ast_log(LOG_ERROR, "Out of free memory\n");
                        return NULL;
@@ -367,13 +367,13 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
                /* fourth word must be 'from' */
                from = strsep(&dupline, " ");
                if (!from || strcmp(from, "from")) {
-                       free(context);
+                       ast_free(context);
                        return NULL;
                }
 
                if (ast_rdlock_contexts()) {
                        ast_log(LOG_ERROR, "Failed to lock context list\n");
-                       free(context);
+                       ast_free(context);
                        return NULL;
                }
 
@@ -385,10 +385,10 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
                                continue;
                        /* walk through all includes and check if it is our context */  
                        if (lookup_ci(c, context) && ++which > a->n)
-                               res = strdup(c_name);
+                               res = ast_strdup(c_name);
                }
                ast_unlock_contexts();
-               free(context);
+               ast_free(context);
                return res;
        }
 
@@ -458,7 +458,7 @@ static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int c
        if ((!strlen(exten)) || (!(strlen(context)))) {
                ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
                        a->argv[3]);
-               free(exten);
+               ast_free(exten);
                return CLI_FAILURE;
        }
 
@@ -481,7 +481,7 @@ static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int c
                }
                ret = CLI_FAILURE;
        }
-       free(exten);
+       ast_free(exten);
        return ret;
 }
 
@@ -593,7 +593,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
 
                ast_unlock_contexts();
        error2:
-               free(exten);
+               ast_free(exten);
        } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
                char *exten = NULL, *context, *cid, *p;
                struct ast_context *c;
@@ -641,7 +641,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
                                while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
                                        snprintf(buffer, sizeof(buffer), "%d", ast_get_extension_priority(priority));
                                        if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
-                                               ret = strdup(buffer);
+                                               ret = ast_strdup(buffer);
                                }
                                break;
                        }
@@ -649,7 +649,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
                }
                ast_unlock_contexts();
        error3:
-               free(exten);
+               ast_free(exten);
        }
        return ret; 
 }
@@ -741,16 +741,16 @@ static char *complete_dialplan_add_include(struct ast_cli_args *a)
                }
                for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
                        if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
-                               ret = strdup(ast_get_context_name(c));
+                               ret = ast_strdup(ast_get_context_name(c));
                ast_unlock_contexts();
                return ret;
        } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
                /* always complete  as 'into' */
-               return (a->n == 0) ? strdup("into") : NULL;
+               return (a->n == 0) ? ast_strdup("into") : NULL;
        } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
                char *context, *dupline, *into;
                const char *s = skip_words(a->line, 3); /* should not fail */
-               context = dupline = strdup(s);
+               context = dupline = ast_strdup(s);
 
                if (!dupline) {
                        ast_log(LOG_ERROR, "Out of free memory\n");
@@ -777,12 +777,12 @@ static char *complete_dialplan_add_include(struct ast_cli_args *a)
                        if (partial_match(ast_get_context_name(c), a->word, len) &&
                                        !lookup_ci(c, context) /* not included yet */ &&
                                        ++which > a->n) {
-                               ret = strdup(ast_get_context_name(c));
+                               ret = ast_strdup(ast_get_context_name(c));
                        }
                }
                ast_unlock_contexts();
        error3:
-               free(context);
+               ast_free(context);
                return ret;
        }
 
@@ -1259,7 +1259,7 @@ static char *complete_dialplan_remove_context(struct ast_cli_args *a)
        /* walk through all contexts */
        while ( !res && (c = ast_walk_contexts(c)) ) {
                if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n) {
-                       res = strdup(ast_get_context_name(c));
+                       res = ast_strdup(ast_get_context_name(c));
                }
        }
        ast_unlock_contexts();
@@ -1272,7 +1272,7 @@ static char *complete_dialplan_add_extension(struct ast_cli_args *a)
        int which = 0;
 
        if (a->pos == 4) {              /* complete 'into' word ... */
-               return (a->n == 0) ? strdup("into") : NULL;
+               return (a->n == 0) ? ast_strdup("into") : NULL;
        } else if (a->pos == 5) { /* complete context */
                struct ast_context *c = NULL;
                int len = strlen(a->word);
@@ -1287,11 +1287,11 @@ static char *complete_dialplan_add_extension(struct ast_cli_args *a)
                /* walk through all contexts */
                while ( !res && (c = ast_walk_contexts(c)) )
                        if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
-                               res = strdup(ast_get_context_name(c));
+                               res = ast_strdup(ast_get_context_name(c));
                ast_unlock_contexts();
                return res;
        } else if (a->pos == 6) {
-               return a->n == 0 ? strdup("replace") : NULL;
+               return a->n == 0 ? ast_strdup("replace") : NULL;
        }
        return NULL;
 }
@@ -1356,7 +1356,7 @@ static char *handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd,
 static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
 {
        if (a->pos == 4)
-               return a->n == 0 ? strdup("into") : NULL;
+               return a->n == 0 ? ast_strdup("into") : NULL;
        else if (a->pos == 5) {
                struct ast_context *c;
                int which = 0;
@@ -1369,7 +1369,7 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
                s = skip_words(a->line, 3);
                if (s == NULL)
                        return NULL;
-               dupline = strdup(s);
+               dupline = ast_strdup(s);
                if (!dupline) {
                        ast_log(LOG_ERROR, "Malloc failure\n");
                        return NULL;
@@ -1389,10 +1389,10 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
                        if (ignorepat) /* there must be one, right ? */
                                found = lookup_c_ip(c, ignorepat);
                        if (!found && ++which > a->n)
-                               ret = strdup(ast_get_context_name(c));
+                               ret = ast_strdup(ast_get_context_name(c));
                }
 
-               free(ignorepat);
+               ast_free(ignorepat);
                ast_unlock_contexts();
                return ret;
        }
@@ -1478,7 +1478,7 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
                                                found = lookup_c_ip(cw, ast_get_ignorepat_name(ip));
                                        }
                                        if (!found)
-                                               ret = strdup(ast_get_ignorepat_name(ip));
+                                               ret = ast_strdup(ast_get_ignorepat_name(ip));
                                }
                        }
                        ast_unlock_context(c);
@@ -1486,12 +1486,12 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
                ast_unlock_contexts();
                return ret;
        } else if (a->pos == 4) {
-                return a->n == 0 ? strdup("from") : NULL;
+                return a->n == 0 ? ast_strdup("from") : NULL;
        } else if (a->pos == 5) { /* XXX check this */
                char *dupline, *duplinet, *ignorepat;
                int len = strlen(a->word);
 
-               dupline = strdup(a->line);
+               dupline = ast_strdup(a->line);
                if (!dupline) {
                        ast_log(LOG_WARNING, "Out of free memory\n");
                        return NULL;
@@ -1503,13 +1503,13 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
                ignorepat = strsep(&duplinet, " ");
 
                if (!ignorepat) {
-                       free(dupline);
+                       ast_free(dupline);
                        return NULL;
                }
 
                if (ast_rdlock_contexts()) {
                        ast_log(LOG_WARNING, "Failed to lock contexts list\n");
-                       free(dupline);
+                       ast_free(dupline);
                        return NULL;
                }
 
@@ -1519,11 +1519,11 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
                        if (!partial_match(ast_get_context_name(c), a->word, len))
                                continue;
                        if (lookup_c_ip(c, ignorepat) && ++which > a->n)
-                               ret = strdup(ast_get_context_name(c));
+                               ret = ast_strdup(ast_get_context_name(c));
                        ast_unlock_context(c);
                }
                ast_unlock_contexts();
-               free(dupline);
+               ast_free(dupline);
                return NULL;
        }
 
index 0b6ec32..5a7fd83 100644 (file)
@@ -68,6 +68,7 @@
 %option bison-locations
 
 %{
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
index c838d79..8fe93f3 100644 (file)
@@ -99,6 +99,7 @@
  *
  */
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
index 27e04c5..c1a6f0f 100644 (file)
@@ -22,6 +22,7 @@
  *
  */
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
index 6aec03b..0539063 100644 (file)
@@ -1,3 +1,4 @@
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 #line 2 "ael_lex.c"
index d72ef0d..7363827 100644 (file)
@@ -27,6 +27,7 @@
        <support_level>extended</support_level>
  ***/
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
index fd21aab..06ffbfb 100644 (file)
@@ -124,7 +124,7 @@ static struct ldap_table_config *table_config_new(const char *table_name)
 
        if (table_name) {
                if (!(p->table_name = ast_strdup(table_name))) {
-                       free(p);
+                       ast_free(p);
                        return NULL;
                }
        }
@@ -238,7 +238,7 @@ static void table_configs_free(void)
                if (c->attributes) {
                        ast_variables_destroy(c->attributes);
                }
-               free(c);
+               ast_free(c);
        }
 
        base_table_config = NULL;
@@ -516,14 +516,14 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
                                                                        is_delimited = 0;
                                                                        pos = 0;
                                                                }
-                                                               free(delim_value);
+                                                               ast_free(delim_value);
                                                                delim_value = NULL;
 
                                                                ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
                                                        } else {
                                                                /* not delimited */
                                                                if (delim_value) {
-                                                                       free(delim_value);
+                                                                       ast_free(delim_value);
                                                                        delim_value = NULL;
                                                                }
                                                                ast_debug(2, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, valptr);
@@ -1007,7 +1007,7 @@ static struct ast_variable *realtime_ldap(const char *basedn,
                        }
                        p++;
                }
-               free(vars);
+               ast_free(vars);
        }
        return var;
 }
@@ -1066,7 +1066,7 @@ static struct ast_config *realtime_multi_ldap(const char *basedn,
                                p++;
                        }
                }
-               free(vars);
+               ast_free(vars);
        }
        return cfg;
 
@@ -1365,8 +1365,8 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
                ast_log(LOG_WARNING, "Query: %s\n", ast_str_buffer(filter));
 
                ast_mutex_unlock(&ldap_lock);
-               free(filter);
-               free(clean_basedn);
+               ast_free(filter);
+               ast_free(clean_basedn);
                ldap_msgfree(ldap_result_msg);
                ldap_mods_free(ldap_mods, 0);
                return -1;
index e9a6b8f..b8b5278 100644 (file)
@@ -272,7 +272,7 @@ static int profile_cmp_fn(void *obj, void *arg, int flags)
 static void delete_file(struct phoneprov_file *file)
 {
        ast_string_field_free_memory(file);
-       free(file);
+       ast_free(file);
 }
 
 static void profile_destructor(void *obj)
@@ -340,7 +340,7 @@ static int load_file(const char *filename, char **ret)
                return -2;
 
        if (len != fread(*ret, sizeof(char), len, f)) {
-               free(*ret);
+               ast_free(*ret);
                *ret = NULL;
                return -3;
        }
index 87727d8..e1d9d40 100644 (file)
@@ -340,7 +340,7 @@ static int cops_getmsg (int sfd, struct copsmsg *recmsg)
        recmsg->length = ntohl(*((uint32_t *) (buf + 4)));
        /* Eg KA msg*/
        if (recmsg->clienttype != 0x8008 ) {
-               if (!(recmsg->msg = malloc(recmsg->length - COPS_HEADER_SIZE))) {
+               if (!(recmsg->msg = ast_malloc(recmsg->length - COPS_HEADER_SIZE))) {
                        return -1;
                }
                lent = recv(sfd, recmsg->msg, recmsg->length - COPS_HEADER_SIZE, MSG_DONTWAIT);
@@ -353,12 +353,12 @@ static int cops_getmsg (int sfd, struct copsmsg *recmsg)
                while (len < recmsg->length) {
                        if (len == COPS_HEADER_SIZE) {
                                /* 1st round */
-                               if (!(recmsg->object = malloc(sizeof(struct pktcobj)))) {
+                               if (!(recmsg->object = ast_malloc(sizeof(struct pktcobj)))) {
                                        return -1;
                                }
                                pobject = recmsg->object;
                        } else {
-                               if (!(pobject->next = malloc(sizeof(struct pktcobj)))) {
+                               if (!(pobject->next = ast_malloc(sizeof(struct pktcobj)))) {
                                        return -1;
                                }
                                pobject = pobject->next;
@@ -373,7 +373,7 @@ static int cops_getmsg (int sfd, struct copsmsg *recmsg)
                        pobject->length = ntohs(*ubuf);
                        pobject->cnum = *(buf + 2);
                        pobject->ctype = *(buf + 3);
-                       if (!(pobject->contents = malloc(pobject->length - COPS_OBJECT_HEADER_SIZE))) {
+                       if (!(pobject->contents = ast_malloc(pobject->length - COPS_OBJECT_HEADER_SIZE))) {
                                return -1;
                        }
                        lent = recv(sfd, pobject->contents, pobject->length - COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT);
@@ -402,7 +402,7 @@ static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
                ast_log(LOG_WARNING, "COPS: invalid msg size!!!\n");
                return -1;
        }
-       if (!(buf = malloc((size_t) sendmsg->length))) {
+       if (!(buf = ast_malloc((size_t) sendmsg->length))) {
                return -1;
        }
        *buf = sendmsg->verflag ;
@@ -419,7 +419,7 @@ static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
                        ast_debug(3, "COPS: Sending Object : cnum: %i ctype %i len: %i\n", pobject->cnum, pobject->ctype, pobject->length);
                        if (sendmsg->length < bufpos + pobject->length) {
                                ast_log(LOG_WARNING, "COPS: Invalid msg size len: %u objectlen: %i\n", sendmsg->length, pobject->length);
-                               free(buf);
+                               ast_free(buf);
                                return -1;
                        }
                        *(uint16_t *) (buf + bufpos) = htons(pobject->length);
@@ -427,7 +427,7 @@ static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
                        *(buf + bufpos + 3) = pobject->ctype;
                        if (sendmsg->length < pobject->length + bufpos) {
                                ast_log(LOG_WARNING, "COPS: Error sum of object len more the msg len %u < %i\n", sendmsg->length, pobject->length + bufpos);
-                               free(buf);
+                               ast_free(buf);
                                return -1;
                        }
                        memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4);
@@ -444,18 +444,18 @@ static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
 #endif
        if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) {
                ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno);
-               free(buf);
+               ast_free(buf);
                return -2;
        }
 #undef SENDFLAGS
-       free(buf);
+       ast_free(buf);
        return 0;
 }
 
 static void cops_freemsg(struct copsmsg *p)
 {
        struct pktcobj *pnext;
-       free(p->msg);
+       ast_free(p->msg);
        p->msg = NULL;
        while (p->object != NULL) {
                        pnext = p->object->next;
@@ -555,8 +555,8 @@ static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts,
        
        gate->in_transaction = time(NULL);
 
-       if (!(gateset = malloc(sizeof(struct copsmsg)))) {
-               free(gateset);
+       if (!(gateset = ast_malloc(sizeof(struct copsmsg)))) {
+               ast_free(gateset);
                return NULL;
        }
        gateset->msg = NULL;
@@ -565,67 +565,67 @@ static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts,
        gateset->clienttype = 0x8008; /* =PacketCable */
        
        /* Handle object */
-       gateset->object = malloc(sizeof(struct pktcobj));
+       gateset->object = ast_malloc(sizeof(struct pktcobj));
        if (!gateset->object) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4;
        gateset->object->cnum = 1; /* Handle */
        gateset->object->ctype = 1; /* client */
-       if (!(gateset->object->contents = malloc(sizeof(uint32_t)))) {
+       if (!(gateset->object->contents = ast_malloc(sizeof(uint32_t)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        *((uint32_t *) gateset->object->contents) = htonl(cmts->handle);
 
        /* Context Object */
-       if (!(gateset->object->next = malloc(sizeof(struct pktcobj)))) {
+       if (!(gateset->object->next = ast_malloc(sizeof(struct pktcobj)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4;
        gateset->object->next->cnum = 2; /* Context */
        gateset->object->next->ctype = 1; /* Context */
-       if (!(gateset->object->next->contents = malloc(sizeof(uint32_t)))) {
+       if (!(gateset->object->next->contents = ast_malloc(sizeof(uint32_t)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        *((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */
 
        /* Decision Object: Flags */
-       if (!(gateset->object->next->next = malloc(sizeof(struct pktcobj)))) {
+       if (!(gateset->object->next->next = ast_malloc(sizeof(struct pktcobj)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4;
        gateset->object->next->next->cnum = 6; /* Decision */
        gateset->object->next->next->ctype = 1; /* Flags */
-       if (!(gateset->object->next->next->contents = malloc(sizeof(uint32_t)))) {
+       if (!(gateset->object->next->next->contents = ast_malloc(sizeof(uint32_t)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        *((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */
 
        /* Decision Object: Data */
-       if (!(gateset->object->next->next->next = malloc(sizeof(struct pktcobj)))) {
+       if (!(gateset->object->next->next->next = ast_malloc(sizeof(struct pktcobj)))) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        gateset->object->next->next->next->length = COPS_OBJECT_HEADER_SIZE + ((cmd != GATE_INFO && cmd != GATE_DEL) ? GATE_SET_OBJ_SIZE : GATE_INFO_OBJ_SIZE) + ((cmd == GATE_SET_HAVE_GATEID) ? GATEID_OBJ_SIZE : 0);
        gateset->object->next->next->next->cnum = 6; /* Decision */
        gateset->object->next->next->next->ctype = 4; /* Decision Data */
-       gateset->object->next->next->next->contents = malloc(((cmd != GATE_INFO && cmd != GATE_DEL) ? GATE_SET_OBJ_SIZE : GATE_INFO_OBJ_SIZE) + ((cmd == GATE_SET_HAVE_GATEID) ? GATEID_OBJ_SIZE : 0));
+       gateset->object->next->next->next->contents = ast_malloc(((cmd != GATE_INFO && cmd != GATE_DEL) ? GATE_SET_OBJ_SIZE : GATE_INFO_OBJ_SIZE) + ((cmd == GATE_SET_HAVE_GATEID) ? GATEID_OBJ_SIZE : 0));
        if (!gateset->object->next->next->next->contents) {
                cops_freemsg(gateset);
-               free(gateset);
+               ast_free(gateset);
                return NULL;
        }
        gateset->object->next->next->next->next = NULL;
@@ -644,7 +644,7 @@ static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts,
        }
        cops_sendmsg(cmts->sfd, gateset);
        cops_freemsg(gateset);
-       free(gateset);
+       ast_free(gateset);
        return gate;
 }
 
@@ -929,11 +929,11 @@ static void *do_pktccops(void *data)
                                                        sendmsg->opcode = 7; /* Client Accept */
                                                        sendmsg->clienttype = 0x8008; /* =PacketCable */
                                                        sendmsg->length = COPS_HEADER_SIZE + COPS_OBJECT_HEADER_SIZE + 4;
-                                                       sendmsg->object = malloc(sizeof(struct pktcobj));
+                                                       sendmsg->object = ast_malloc(sizeof(struct pktcobj));
                                                        sendmsg->object->length = 4 + COPS_OBJECT_HEADER_SIZE;
                                                        sendmsg->object->cnum = 10; /* keppalive timer*/
                                                        sendmsg->object->ctype = 1;
-                                                       sendmsg->object->contents = malloc(sizeof(uint32_t));
+                                                       sendmsg->object->contents = ast_malloc(sizeof(uint32_t));
                                                        *((uint32_t *) sendmsg->object->contents) = htonl(cmts->keepalive & 0x0000ffff);
                                                        sendmsg->object->next = NULL;
                                                        cops_sendmsg(cmts->sfd, sendmsg);
@@ -980,7 +980,7 @@ static void *do_pktccops(void *data)
                                                close(cmts->sfd);
                                        }
                                        AST_LIST_REMOVE_CURRENT(list);
-                                       free(cmts);
+                                       ast_free(cmts);
                                }
                        }
                        AST_LIST_TRAVERSE_SAFE_END;
@@ -1442,13 +1442,13 @@ static void pktccops_unregister_cmtses(void)
                if (cmts->sfd > 0) {
                        close(cmts->sfd);
                }
-               free(cmts);
+               ast_free(cmts);
        }
        AST_LIST_UNLOCK(&cmts_list);
 
        AST_LIST_LOCK(&gate_list);
        while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) {
-               free(gate);
+               ast_free(gate);
        }
        AST_LIST_UNLOCK(&gate_list);
 }
@@ -1458,7 +1458,7 @@ static void pktccops_unregister_ippools(void)
        struct cops_ippool *ippool;
        AST_LIST_LOCK(&ippool_list);
        while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) {
-               free(ippool);
+               ast_free(ippool);
        }
        AST_LIST_UNLOCK(&ippool_list);
 }
index 5cb67e6..bf65ec0 100644 (file)
@@ -4914,7 +4914,7 @@ static void ast_rtp_stop(struct ast_rtp_instance *instance)
 
        if (rtp->red) {
                AST_SCHED_DEL(rtp->sched, rtp->red->schedid);
-               free(rtp->red);
+               ast_free(rtp->red);
                rtp->red = NULL;
        }
 
index c7e0ab2..02f2e4a 100644 (file)
@@ -246,7 +246,7 @@ static void smdi_interface_destroy(void *obj)
        ast_mutex_destroy(&iface->mwi_q_lock);
        ast_cond_destroy(&iface->mwi_q_cond);
 
-       free(iface);
+       ast_free(iface);
 
        ast_module_unref(ast_module_info->self);
 }
@@ -770,7 +770,7 @@ static void destroy_mailbox_mapping(struct mailbox_mapping *mm)
 {
        ast_string_field_free_memory(mm);
        ao2_ref(mm->iface, -1);
-       free(mm);
+       ast_free(mm);
 }
 
 static void destroy_all_mailbox_mappings(void)
@@ -1151,7 +1151,7 @@ static void smdi_msg_datastore_destroy(void *data)
        ao2_cleanup(smd->iface);
        ao2_cleanup(smd->md_msg);
 
-       free(smd);
+       ast_free(smd);
 }
 
 static const struct ast_datastore_info smdi_msg_datastore_info = {
index 197dd75..cba367f 100644 (file)
@@ -106,10 +106,10 @@ static void destroy_test_container(struct test_container *x)
        struct test1 *t1;
        AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&x->entries, t1, list) {
                AST_DLLIST_REMOVE_CURRENT(list);
-               free(t1);
+               ast_free(t1);
        }
        AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
-       free(x);
+       ast_free(x);
 }
 
 /* Macros to test:
@@ -337,7 +337,7 @@ static void dll_tests(void)
 
                if (e == b) {
                        AST_DLLIST_REMOVE_CURRENT(list);  /* C A */
-                       free(b);
+                       ast_free(b);
                        print_list(tc, "C <=> A");
                }
                if (e == a) {
index 051ce79..62c8604 100644 (file)
@@ -43,6 +43,7 @@
        <support_level>extended</support_level>
  ***/
 
+#define WRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 #undef DEBUG_THREADS