core: Don't allow free to mean ast_free (and malloc, etc..).

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
changes/42/42/1
Walter Doekes 11 years ago
parent b8c1130ed1
commit 37179a2b1f

@ -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"); ast_log(LOG_WARNING, "Unable to lock identifiers list\n");
return -1; return -1;
} else { } else {
i = malloc(sizeof(*i)); i = ast_malloc(sizeof(*i));
AST_LIST_TRAVERSE(headp, j, entries) { AST_LIST_TRAVERSE(headp, j, entries) {
if (j->identifier > maxidentifier) { if (j->identifier > maxidentifier) {
maxidentifier = j->identifier; maxidentifier = j->identifier;
@ -247,7 +247,7 @@ static int del_identifier(int identifier, int identifier_type)
if ((i->identifier == identifier) && if ((i->identifier == identifier) &&
(i->identifier_type == identifier_type)) { (i->identifier_type == identifier_type)) {
AST_LIST_REMOVE(headp, i, entries); AST_LIST_REMOVE(headp, i, entries);
free(i); ast_free(i);
found = 1; found = 1;
break; break;
} }

@ -538,7 +538,7 @@ static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
pvt->call_reference = callref; pvt->call_reference = callref;
if (callToken) if (callToken)
pvt->callToken = strdup(callToken); pvt->callToken = ast_strdup(callToken);
/* whether to use gk for this call */ /* whether to use gk for this call */
if (gRasGkMode == RasNoGatekeeper) if (gRasGkMode == RasNoGatekeeper)
@ -645,8 +645,8 @@ static struct ast_channel *ooh323_request(const char *type, struct ast_format_ca
} }
if (peer) { if (peer) {
p->username = strdup(peer->name); p->username = ast_strdup(peer->name);
p->host = strdup(peer->ip); p->host = ast_strdup(peer->ip);
p->port = peer->port; p->port = peer->port;
/* Disable gk as we are going to call a known peer*/ /* Disable gk as we are going to call a known peer*/
/* OO_SETFLAG(p->flags, H323_DISABLEGK); */ /* 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->directrtp = gDirectRTP;
p->earlydirect = gEarlyDirect; p->earlydirect = gEarlyDirect;
p->username = strdup(dest); p->username = ast_strdup(dest);
p->host = strdup(dest); p->host = ast_strdup(dest);
if (port > 0) { if (port > 0) {
p->port = port; 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_mutex_lock(&p->lock);
ast_set_flag(p, H323_OUTGOING); ast_set_flag(p, H323_OUTGOING);
if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) { if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
free(p->callerid_num); ast_free(p->callerid_num);
p->callerid_num = strdup(ast_channel_connected(ast)->id.number.str); 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) { if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
free(p->callerid_name); ast_free(p->callerid_name);
p->callerid_name = strdup(ast_channel_connected(ast)->id.name.str); 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) { } else if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
free(p->callerid_name); ast_free(p->callerid_name);
p->callerid_name = strdup(ast_channel_connected(ast)->id.number.str); p->callerid_name = ast_strdup(ast_channel_connected(ast)->id.number.str);
} else { } else {
ast_channel_connected(ast)->id.name.valid = 1; ast_channel_connected(ast)->id.name.valid = 1;
free(ast_channel_connected(ast)->id.name.str); ast_free(ast_channel_connected(ast)->id.name.str);
ast_channel_connected(ast)->id.name.str = strdup(gCallerID); ast_channel_connected(ast)->id.name.str = ast_strdup(gCallerID);
free(p->callerid_name); ast_free(p->callerid_name);
p->callerid_name = strdup(ast_channel_connected(ast)->id.name.str); p->callerid_name = ast_strdup(ast_channel_connected(ast)->id.name.str);
} }
/* Retrieve vars */ /* 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"))) { if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323DIALEDDIGITS"))) {
ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits)); ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits));
if(!p->callerid_num) if(!p->callerid_num)
p->callerid_num = strdup(val); p->callerid_num = ast_strdup(val);
} }
if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) { if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) {
@ -1113,7 +1113,7 @@ static int ooh323_answer(struct ast_channel *ast)
if (p) { if (p) {
ast_mutex_lock(&p->lock); 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) { if (ast_channel_state(ast) != AST_STATE_UP) {
ast_channel_lock(ast); ast_channel_lock(ast);
if (!p->alertsent) { if (!p->alertsent) {
@ -1132,7 +1132,7 @@ static int ooh323_answer(struct ast_channel *ast)
ooAnswerCall(p->callToken); ooAnswerCall(p->callToken);
} }
if (callToken) { if (callToken) {
free(callToken); ast_free(callToken);
} }
ast_mutex_unlock(&p->lock); 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; if (!p) return -1;
ast_mutex_lock(&p->lock); 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); ast_mutex_unlock(&p->lock);
if (!callToken) { 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); ast_verb(0, "++++ ooh323_indicate %d on %s is %d\n", condition, callToken, res);
} }
free(callToken); ast_free(callToken);
return res; return res;
} }
@ -1815,25 +1815,25 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
if (call->remoteDisplayName) { 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) { if (ooCallGetCallingPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK) {
p->callerid_num = strdup(number); p->callerid_num = ast_strdup(number);
} }
if (call->remoteAliases) { if (call->remoteAliases) {
for (alias = call->remoteAliases; alias; alias = alias->next) { for (alias = call->remoteAliases; alias; alias = alias->next) {
if (alias->type == T_H225AliasAddress_h323_ID) { if (alias->type == T_H225AliasAddress_h323_ID) {
if (!p->callerid_name) { 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)); ast_copy_string(p->caller_h323id, alias->value, sizeof(p->caller_h323id));
} }
else if(alias->type == T_H225AliasAddress_dialedDigits) else if(alias->type == T_H225AliasAddress_dialedDigits)
{ {
if(!p->callerid_num) 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, ast_copy_string(p->caller_dialedDigits, alias->value,
sizeof(p->caller_dialedDigits)); sizeof(p->caller_dialedDigits));
} }
@ -1874,7 +1874,7 @@ int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
user = find_user(p->callerid_name, call->remoteIP); user = find_user(p->callerid_name, call->remoteIP);
if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) { if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
ast_mutex_lock(&user->lock); 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) : p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
ast_strdup(user->name); ast_strdup(user->name);
ast_copy_string(p->context, user->context, sizeof(p->context)); 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); ast_mutex_unlock(&user->lock);
} else { } else {
if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) { if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
p->username = strdup(call->remoteIP); p->username = ast_strdup(call->remoteIP);
p->directrtp = gDirectRTP; p->directrtp = gDirectRTP;
p->earlydirect = gEarlyDirect; p->earlydirect = gEarlyDirect;
} else { } else {
@ -2273,7 +2273,7 @@ int onCallCleared(ooCallData *call)
} }
ast_mutex_unlock(&userl.lock); ast_mutex_unlock(&userl.lock);
free(user); ast_free(user);
} }
if (gH323Debug) if (gH323Debug)
@ -2305,13 +2305,13 @@ void ooh323_delete_peer(struct ooh323_peer *peer)
} }
ast_mutex_unlock(&peerl.lock); ast_mutex_unlock(&peerl.lock);
if(peer->h323id) free(peer->h323id); ast_free(peer->h323id);
if(peer->email) free(peer->email); ast_free(peer->email);
if(peer->url) free(peer->url); ast_free(peer->url);
if(peer->e164) free(peer->e164); ast_free(peer->e164);
ao2_cleanup(peer->cap); ao2_cleanup(peer->cap);
free(peer); ast_free(peer);
} }
if (gH323Debug) if (gH323Debug)
@ -2797,8 +2797,8 @@ int reload_config(int reload)
while (cur) { while (cur) {
prev = cur; prev = cur;
cur = cur->next; cur = cur->next;
free(prev->value); ast_free(prev->value);
free(prev); ast_free(prev);
} }
gAliasList = NULL; gAliasList = NULL;
ooH323EpClearAllAliases(); ooH323EpClearAllAliases();
@ -2913,7 +2913,7 @@ int reload_config(int reload)
ast_copy_string(gCallerID, v->value, sizeof(gCallerID)); ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
} }
pNewAlias->type = T_H225AliasAddress_h323_ID; pNewAlias->type = T_H225AliasAddress_h323_ID;
pNewAlias->value = strdup(v->value); pNewAlias->value = ast_strdup(v->value);
pNewAlias->next = gAliasList; pNewAlias->next = gAliasList;
gAliasList = pNewAlias; gAliasList = pNewAlias;
pNewAlias = NULL; pNewAlias = NULL;
@ -2934,7 +2934,7 @@ int reload_config(int reload)
return 1; return 1;
} }
pNewAlias->type = T_H225AliasAddress_dialedDigits; pNewAlias->type = T_H225AliasAddress_dialedDigits;
pNewAlias->value = strdup(v->value); pNewAlias->value = ast_strdup(v->value);
pNewAlias->next = gAliasList; pNewAlias->next = gAliasList;
gAliasList = pNewAlias; gAliasList = pNewAlias;
pNewAlias = NULL; pNewAlias = NULL;
@ -2949,7 +2949,7 @@ int reload_config(int reload)
return 1; return 1;
} }
pNewAlias->type = T_H225AliasAddress_email_ID; pNewAlias->type = T_H225AliasAddress_email_ID;
pNewAlias->value = strdup(v->value); pNewAlias->value = ast_strdup(v->value);
pNewAlias->next = gAliasList; pNewAlias->next = gAliasList;
gAliasList = pNewAlias; gAliasList = pNewAlias;
pNewAlias = NULL; pNewAlias = NULL;
@ -4094,22 +4094,22 @@ int ooh323_destroy(struct ooh323_pvt *p)
} }
if (cur->username) { if (cur->username) {
free(cur->username); ast_free(cur->username);
cur->username = 0; cur->username = 0;
} }
if (cur->host) { if (cur->host) {
free(cur->host); ast_free(cur->host);
cur->host = 0; cur->host = 0;
} }
if (cur->callerid_name) { if (cur->callerid_name) {
free(cur->callerid_name); ast_free(cur->callerid_name);
cur->callerid_name = 0; cur->callerid_name = 0;
} }
if (cur->callerid_num) { if (cur->callerid_num) {
free(cur->callerid_num); ast_free(cur->callerid_num);
cur->callerid_num = 0; cur->callerid_num = 0;
} }
@ -4151,7 +4151,7 @@ int ooh323_destroy(struct ooh323_pvt *p)
user->inUse--; user->inUse--;
ast_mutex_unlock(&user->lock); ast_mutex_unlock(&user->lock);
} }
free(cur->neighbor.user); ast_free(cur->neighbor.user);
} }
} else { } else {
/* outgoing limit decrement here !!! */ /* outgoing limit decrement here !!! */
@ -4181,10 +4181,10 @@ int delete_peers()
cur = cur->next; cur = cur->next;
ast_mutex_destroy(&prev->lock); ast_mutex_destroy(&prev->lock);
if(prev->h323id) free(prev->h323id); ast_free(prev->h323id);
if(prev->email) free(prev->email); ast_free(prev->email);
if(prev->url) free(prev->url); ast_free(prev->url);
if(prev->e164) free(prev->e164); ast_free(prev->e164);
if(prev->rtpmask) { if(prev->rtpmask) {
ast_mutex_lock(&prev->rtpmask->lock); ast_mutex_lock(&prev->rtpmask->lock);
prev->rtpmask->inuse--; prev->rtpmask->inuse--;
@ -4192,10 +4192,10 @@ int delete_peers()
if (prev->rtpmask->inuse == 0) { if (prev->rtpmask->inuse == 0) {
regfree(&prev->rtpmask->regex); regfree(&prev->rtpmask->regex);
ast_mutex_destroy(&prev->rtpmask->lock); ast_mutex_destroy(&prev->rtpmask->lock);
free(prev->rtpmask); ast_free(prev->rtpmask);
} }
} }
free(prev); ast_free(prev);
if (cur == peerl.peers) { if (cur == peerl.peers) {
break; break;
@ -4223,11 +4223,11 @@ int delete_users()
if (prev->rtpmask->inuse == 0) { if (prev->rtpmask->inuse == 0) {
regfree(&prev->rtpmask->regex); regfree(&prev->rtpmask->regex);
ast_mutex_destroy(&prev->rtpmask->lock); ast_mutex_destroy(&prev->rtpmask->lock);
free(prev->rtpmask); ast_free(prev->rtpmask);
} }
} }
ao2_cleanup(prev->cap); ao2_cleanup(prev->cap);
free(prev); ast_free(prev);
if (cur == userl.users) { if (cur == userl.users) {
break; break;
} }
@ -4339,8 +4339,8 @@ static int unload_module(void)
while (cur) { while (cur) {
prev = cur; prev = cur;
cur = cur->next; cur = cur->next;
free(prev->value); ast_free(prev->value);
free(prev); ast_free(prev);
} }
gAliasList = NULL; 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)); 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 (!callToken) {
if (gH323Debug) { 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); ast_mutex_unlock(&p->lock);
free(callToken); ast_free(callToken);
return 0; return 0;
} }

@ -15,6 +15,7 @@
*****************************************************************************/ *****************************************************************************/
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "ooasn1.h" #include "ooasn1.h"
#include <stdlib.h> #include <stdlib.h>
@ -157,11 +158,11 @@ int setPERBuffer (OOCTXT* pctxt,
OOCTXT* newContext () OOCTXT* newContext ()
{ {
/* OOCTXT* pctxt = (OOCTXT*) ASN1CRTMALLOC0 (sizeof(OOCTXT)); */ /* OOCTXT* pctxt = (OOCTXT*) ASN1CRTMALLOC0 (sizeof(OOCTXT)); */
OOCTXT* pctxt = (OOCTXT*) malloc (sizeof(OOCTXT)); OOCTXT* pctxt = ast_malloc(sizeof(OOCTXT));
if (pctxt) { if (pctxt) {
if (initContext(pctxt) != ASN_OK) { if (initContext(pctxt) != ASN_OK) {
/* ASN1CRTFREE0 (pctxt); */ /* ASN1CRTFREE0 (pctxt); */
free(pctxt); ast_free(pctxt);
pctxt = 0; pctxt = 0;
} }
pctxt->flags |= ASN1DYNCTXT; pctxt->flags |= ASN1DYNCTXT;

@ -18,6 +18,7 @@
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
#include <stdlib.h> #include <stdlib.h>
#include "ooasn1.h" #include "ooasn1.h"
@ -89,7 +90,7 @@ int errAddStrParm (ASN1ErrInfo* pErrInfo, const char* errprm_p)
#if defined(_NO_THREADS) || !defined(_NO_MALLOC) #if defined(_NO_THREADS) || !defined(_NO_MALLOC)
if (pErrInfo->parmcnt < ASN_K_MAXERRP) { if (pErrInfo->parmcnt < ASN_K_MAXERRP) {
/* char* tmpstr = (char*) ASN1CRTMALLOC0 (strlen(errprm_p)+1); */ /* 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); strcpy (tmpstr, errprm_p);
pErrInfo->parms[pErrInfo->parmcnt] = tmpstr; pErrInfo->parms[pErrInfo->parmcnt] = tmpstr;
pErrInfo->parmcnt++; pErrInfo->parmcnt++;
@ -118,7 +119,7 @@ void errFreeParms (ASN1ErrInfo* pErrInfo)
for (i = 0; i < pErrInfo->parmcnt; i++) for (i = 0; i < pErrInfo->parmcnt; i++)
/* ASN1CRTFREE0 ((char*)pErrInfo->parms[i]); */ /* ASN1CRTFREE0 ((char*)pErrInfo->parms[i]); */
free ((char*)pErrInfo->parms[i]); ast_free((char*)pErrInfo->parms[i]);
#endif #endif
pErrInfo->parmcnt = 0; pErrInfo->parmcnt = 0;

@ -15,6 +15,7 @@
*****************************************************************************/ *****************************************************************************/
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
#include <stdlib.h> #include <stdlib.h>
#include "memheap.h" #include "memheap.h"
@ -176,13 +177,13 @@ void* memHeapAlloc (void** ppvMemHeap, int nbytes)
/* allocate raw block */ /* allocate raw block */
data = malloc (nbytes); data = ast_malloc(nbytes);
if (data == NULL) { if (data == NULL) {
return NULL; return NULL;
} }
pMemLink = memHeapAddBlock (ppMemLink, data, RTMEMMALLOC | RTMEMRAW); pMemLink = memHeapAddBlock (ppMemLink, data, RTMEMMALLOC | RTMEMRAW);
if (pMemLink == 0) { if (pMemLink == 0) {
free (data); ast_free(data);
return NULL; return NULL;
} }
/* save size of the RAW memory block behind the pMemLink */ /* 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)); ((((ASN1UINT)dataUnits) * 8u) + sizeof (OSMemBlk));
} }
pmem = (ASN1OCTET*) malloc (allocSize + sizeof (OSMemLink)); pmem = (ASN1OCTET*) ast_malloc(allocSize + sizeof (OSMemLink));
if (0 != pmem) { if (0 != pmem) {
OSMemElemDescr* pElem; OSMemElemDescr* pElem;
@ -357,7 +358,7 @@ void* memHeapAlloc (void** ppvMemHeap, int nbytes)
if (memHeapAddBlock (ppMemLink, pMemBlk, RTMEMSTD | RTMEMLINK) == 0) if (memHeapAddBlock (ppMemLink, pMemBlk, RTMEMSTD | RTMEMLINK) == 0)
{ {
free (pmem); ast_free(pmem);
ast_mutex_unlock(&pMemHeap->pLock); ast_mutex_unlock(&pMemHeap->pLock);
return NULL; return NULL;
} }
@ -437,12 +438,12 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
if ((pMemLink->blockType & RTMEMLINK) && if ((pMemLink->blockType & RTMEMLINK) &&
(pMemLink->blockType & RTMEMMALLOC)) (pMemLink->blockType & RTMEMMALLOC))
{ {
free (pMemLink); ast_free(pMemLink);
} }
else { else {
if (pMemLink->blockType & RTMEMMALLOC) if (pMemLink->blockType & RTMEMMALLOC)
free (pMemLink->pMemBlk); ast_free(pMemLink->pMemBlk);
free (pMemLink); ast_free(pMemLink);
} }
ast_mutex_unlock(&pMemHeap->pLock); ast_mutex_unlock(&pMemHeap->pLock);
return; return;
@ -553,11 +554,11 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
FILLFREEMEM (pMemBlk->plink, sizeof (*pMemBlk->plink)); FILLFREEMEM (pMemBlk->plink, sizeof (*pMemBlk->plink));
FILLFREEMEM (pMemBlk->data, (pMemBlk->nunits * 8u)); FILLFREEMEM (pMemBlk->data, (pMemBlk->nunits * 8u));
free (pMemBlk->plink); ast_free(pMemBlk->plink);
if (!(blockType & RTMEMLINK)) { if (!(blockType & RTMEMLINK)) {
FILLFREEMEM (pMemBlk, sizeof (*pMemBlk)); FILLFREEMEM (pMemBlk, sizeof (*pMemBlk));
free (pMemBlk); ast_free(pMemBlk);
} }
RTMEMDIAG2 ("memHeapFreePtr: pMemBlk = 0x%x was freed\n", RTMEMDIAG2 ("memHeapFreePtr: pMemBlk = 0x%x was freed\n",
pMemBlk); pMemBlk);
@ -748,7 +749,7 @@ void* memHeapRealloc (void** ppvMemHeap, void* mem_p, int nbytes_)
pMemLink->pMemBlk == mem_p) pMemLink->pMemBlk == mem_p)
{ {
if (pMemLink->blockType & RTMEMMALLOC) { if (pMemLink->blockType & RTMEMMALLOC) {
void *newMemBlk = realloc (pMemLink->pMemBlk, nbytes_); void *newMemBlk = ast_realloc(pMemLink->pMemBlk, nbytes_);
if (newMemBlk == 0) if (newMemBlk == 0)
return 0; return 0;
pMemLink->pMemBlk = newMemBlk; pMemLink->pMemBlk = newMemBlk;
@ -1038,8 +1039,8 @@ void memHeapFreeAll (void** ppvMemHeap)
if (((pMemLink2->blockType & RTMEMSTD) || if (((pMemLink2->blockType & RTMEMSTD) ||
(pMemLink2->blockType & RTMEMMALLOC)) && (pMemLink2->blockType & RTMEMMALLOC)) &&
!(pMemLink2->blockType & RTMEMLINK)) !(pMemLink2->blockType & RTMEMLINK))
free (pMemLink2->pMemBlk); ast_free(pMemLink2->pMemBlk);
free (pMemLink2); ast_free(pMemLink2);
} }
} }
ast_mutex_unlock(&pMemHeap->pLock); ast_mutex_unlock(&pMemHeap->pLock);
@ -1075,12 +1076,12 @@ void memHeapRelease (void** ppvMemHeap)
pMemLink2 = pMemLink; pMemLink2 = pMemLink;
pMemLink = pMemLink2->pnext; pMemLink = pMemLink2->pnext;
free (pMemLink2); ast_free(pMemLink2);
} }
if ((*ppMemHeap)->flags & RT_MH_FREEHEAPDESC) { if ((*ppMemHeap)->flags & RT_MH_FREEHEAPDESC) {
ast_mutex_destroy(&pMemHeap->pLock); ast_mutex_destroy(&pMemHeap->pLock);
free (*ppMemHeap); ast_free(*ppMemHeap);
} }
*ppMemHeap = 0; *ppMemHeap = 0;
} }
@ -1215,8 +1216,7 @@ static OSMemLink* memHeapAddBlock (OSMemLink** ppMemLink,
if (blockType & RTMEMLINK) if (blockType & RTMEMLINK)
pMemLink = (OSMemLink*) (((ASN1OCTET*)pMemBlk) - sizeof (OSMemLink)); pMemLink = (OSMemLink*) (((ASN1OCTET*)pMemBlk) - sizeof (OSMemLink));
else { else {
pMemLink = (OSMemLink*) malloc ( pMemLink = ast_malloc(sizeof(OSMemLink) + sizeof(int));
sizeof(OSMemLink) + sizeof (int));
if (pMemLink == 0) return 0; if (pMemLink == 0) return 0;
/* An extra integer is necessary to save a size of a RAW memory block /* An extra integer is necessary to save a size of a RAW memory block
to perform rtMemRealloc through malloc/memcpy/free */ to perform rtMemRealloc through malloc/memcpy/free */
@ -1339,7 +1339,7 @@ int memHeapCreate (void** ppvMemHeap)
OSMemHeap* pMemHeap; OSMemHeap* pMemHeap;
if (ppvMemHeap == 0) return ASN_E_INVPARAM; if (ppvMemHeap == 0) return ASN_E_INVPARAM;
pMemHeap = (OSMemHeap*) malloc (sizeof (OSMemHeap)); pMemHeap = ast_malloc(sizeof (OSMemHeap));
if (pMemHeap == NULL) return ASN_E_NOMEM; if (pMemHeap == NULL) return ASN_E_NOMEM;
memset (pMemHeap, 0, sizeof (OSMemHeap)); memset (pMemHeap, 0, sizeof (OSMemHeap));
pMemHeap->defBlkSize = g_defBlkSize; pMemHeap->defBlkSize = g_defBlkSize;

@ -16,6 +16,7 @@
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "ootrace.h" #include "ootrace.h"
#include "ootypes.h" #include "ootypes.h"
@ -366,13 +367,13 @@ int ooCleanCall(OOH323CallData *call)
if ((call->rtpMask->inuse) == 0) { if ((call->rtpMask->inuse) == 0) {
regfree(&call->rtpMask->regex); regfree(&call->rtpMask->regex);
ast_mutex_destroy(&call->rtpMask->lock); ast_mutex_destroy(&call->rtpMask->lock);
free(call->rtpMask); ast_free(call->rtpMask);
} }
} }
if ((pctxt = call->msgctxt) != NULL) { if ((pctxt = call->msgctxt) != NULL) {
freeContext(pctxt); freeContext(pctxt);
free(pctxt); ast_free(pctxt);
call->msgctxt = NULL; call->msgctxt = NULL;
} }
/* May !!!! Fix it !! */ /* May !!!! Fix it !! */

@ -57,13 +57,13 @@ int ooCreateCallCmdConnection(OOH323CallData* call)
OOTRACEINFO2("INFO: create cmd connect for call: %lx\n", 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); ast_mutex_init(call->CmdChanLock);
if ((ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, thePipe)) == -1) { if ((ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, thePipe)) == -1) {
ast_mutex_destroy(call->CmdChanLock); ast_mutex_destroy(call->CmdChanLock);
free(call->CmdChanLock); ast_free(call->CmdChanLock);
call->CmdChanLock = NULL; call->CmdChanLock = NULL;
return OO_FAILED; return OO_FAILED;
} }
@ -94,7 +94,7 @@ int ooCloseCallCmdConnection(OOH323CallData* call)
call->CmdChan = 0; call->CmdChan = 0;
ast_mutex_unlock(call->CmdChanLock); ast_mutex_unlock(call->CmdChanLock);
ast_mutex_destroy(call->CmdChanLock); ast_mutex_destroy(call->CmdChanLock);
free(call->CmdChanLock); ast_free(call->CmdChanLock);
call->CmdChanLock = NULL; call->CmdChanLock = NULL;
return OO_OK; return OO_OK;
@ -267,9 +267,9 @@ int ooReadAndProcessStackCommand()
default: OOTRACEERR1("ERROR:Unknown command\n"); default: OOTRACEERR1("ERROR:Unknown command\n");
} }
} }
if(cmd.param1) free(cmd.param1); ast_free(cmd.param1);
if(cmd.param2) free(cmd.param2); ast_free(cmd.param2);
if(cmd.param3) free(cmd.param3); ast_free(cmd.param3);
} }
@ -302,7 +302,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
bPoint += sizeof(OOStackCommand); bPoint += sizeof(OOStackCommand);
if (cmd.plen1 > 0) { if (cmd.plen1 > 0) {
cmd.param1 = malloc(cmd.plen1 + 1); cmd.param1 = ast_malloc(cmd.plen1 + 1);
if (!cmd.param1) if (!cmd.param1)
return OO_FAILED; return OO_FAILED;
memset(cmd.param1, 0, cmd.plen1 + 1); memset(cmd.param1, 0, cmd.plen1 + 1);
@ -311,7 +311,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
} }
if (cmd.plen2 > 0) { if (cmd.plen2 > 0) {
cmd.param2 = malloc(cmd.plen2 + 1); cmd.param2 = ast_malloc(cmd.plen2 + 1);
if (!cmd.param2) if (!cmd.param2)
return OO_FAILED; return OO_FAILED;
memset(cmd.param2, 0, cmd.plen2 + 1); memset(cmd.param2, 0, cmd.plen2 + 1);
@ -320,7 +320,7 @@ int ooReadAndProcessCallStackCommand(OOH323CallData* call)
} }
if (cmd.plen3 > 0) { if (cmd.plen3 > 0) {
cmd.param3 = malloc(cmd.plen3 + 1); cmd.param3 = ast_malloc(cmd.plen3 + 1);
if (!cmd.param3) if (!cmd.param3)
return OO_FAILED; return OO_FAILED;
memset(cmd.param3, 0, cmd.plen3 + 1); memset(cmd.param3, 0, cmd.plen3 + 1);

@ -79,7 +79,7 @@ OOStkCmdStat ooMakeCall
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_MAKECALL; cmd.type = OO_CMD_MAKECALL;
cmd.param1 = (void*) malloc(strlen(dest)+1); cmd.param1 = ast_malloc(strlen(dest)+1);
if(!cmd.param1) if(!cmd.param1)
{ {
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
@ -87,10 +87,10 @@ OOStkCmdStat ooMakeCall
strcpy((char*)cmd.param1, dest); strcpy((char*)cmd.param1, dest);
cmd.param2 = (void*) malloc(strlen(callToken)+1); cmd.param2 = ast_malloc(strlen(callToken)+1);
if(!cmd.param2) if(!cmd.param2)
{ {
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
@ -101,11 +101,11 @@ OOStkCmdStat ooMakeCall
cmd.param3 = 0; cmd.param3 = 0;
} }
else { else {
cmd.param3 = (void*) malloc(sizeof(ooCallOptions)); cmd.param3 = ast_malloc(sizeof(ooCallOptions));
if(!cmd.param3) if(!cmd.param3)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions)); memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions));
@ -113,9 +113,9 @@ OOStkCmdStat ooMakeCall
if(ooWriteStackCommand(&cmd) != OO_OK) if(ooWriteStackCommand(&cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
if(cmd.param3) free(cmd.param3); if(cmd.param3) ast_free(cmd.param3);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
@ -149,7 +149,7 @@ OOStkCmdStat ooRunCall
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_MAKECALL; cmd.type = OO_CMD_MAKECALL;
cmd.param1 = (void*) malloc(strlen(dest)+1); cmd.param1 = ast_malloc(strlen(dest)+1);
if(!cmd.param1) if(!cmd.param1)
{ {
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
@ -158,10 +158,10 @@ OOStkCmdStat ooRunCall
cmd.plen1 = strlen(dest); cmd.plen1 = strlen(dest);
cmd.param2 = (void*) malloc(strlen(callToken)+1); cmd.param2 = ast_malloc(strlen(callToken)+1);
if(!cmd.param2) if(!cmd.param2)
{ {
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
@ -173,11 +173,11 @@ OOStkCmdStat ooRunCall
cmd.param3 = 0; cmd.param3 = 0;
} }
else { else {
cmd.param3 = (void*) malloc(sizeof(ooCallOptions)); cmd.param3 = ast_malloc(sizeof(ooCallOptions));
if(!cmd.param3) if(!cmd.param3)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions)); memcpy((void*)cmd.param3, opts, sizeof(ooCallOptions));
@ -186,16 +186,16 @@ OOStkCmdStat ooRunCall
if(ooWriteCallStackCommand(call, &cmd) != OO_OK) if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
if(cmd.param3) free(cmd.param3); if(cmd.param3) ast_free(cmd.param3);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
if(cmd.param3) free(cmd.param3); if(cmd.param3) ast_free(cmd.param3);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -223,7 +223,7 @@ OOStkCmdStat ooManualRingback(const char *callToken)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_MANUALRINGBACK; cmd.type = OO_CMD_MANUALRINGBACK;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
if(!cmd.param1) if(!cmd.param1)
{ {
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
@ -233,11 +233,11 @@ OOStkCmdStat ooManualRingback(const char *callToken)
if(ooWriteCallStackCommand(call,&cmd) != OO_OK) if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -267,7 +267,7 @@ OOStkCmdStat ooManualProgress(const char *callToken)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_MANUALPROGRESS; cmd.type = OO_CMD_MANUALPROGRESS;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
if(!cmd.param1) if(!cmd.param1)
{ {
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
@ -277,11 +277,11 @@ OOStkCmdStat ooManualProgress(const char *callToken)
if(ooWriteCallStackCommand(call, &cmd) != OO_OK) if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -309,7 +309,7 @@ OOStkCmdStat ooAnswerCall(const char *callToken)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_ANSCALL; cmd.type = OO_CMD_ANSCALL;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
if(!cmd.param1) if(!cmd.param1)
{ {
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
@ -319,11 +319,11 @@ OOStkCmdStat ooAnswerCall(const char *callToken)
if(ooWriteCallStackCommand(call, &cmd) != OO_OK) if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -350,12 +350,12 @@ OOStkCmdStat ooForwardCall(const char* callToken, char *dest)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_FWDCALL; cmd.type = OO_CMD_FWDCALL;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
cmd.param2 = (void*) malloc(strlen(dest)+1); cmd.param2 = ast_malloc(strlen(dest)+1);
if(!cmd.param1 || !cmd.param2) if(!cmd.param1 || !cmd.param2)
{ {
if(cmd.param1) free(cmd.param1); /* Release memory */ if(cmd.param1) ast_free(cmd.param1); /* Release memory */
if(cmd.param2) free(cmd.param2); if(cmd.param2) ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
strcpy((char*)cmd.param1, callToken); strcpy((char*)cmd.param1, callToken);
@ -365,12 +365,12 @@ OOStkCmdStat ooForwardCall(const char* callToken, char *dest)
if(ooWriteCallStackCommand(call, &cmd) != OO_OK) if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -399,14 +399,14 @@ OOStkCmdStat ooHangCall(const char* callToken, OOCallClearReason reason, int q93
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_HANGCALL; cmd.type = OO_CMD_HANGCALL;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
cmd.param2 = (void*) malloc(sizeof(OOCallClearReason)); cmd.param2 = ast_malloc(sizeof(OOCallClearReason));
cmd.param3 = (void*) malloc(sizeof(int)); cmd.param3 = ast_malloc(sizeof(int));
if(!cmd.param1 || !cmd.param2 || !cmd.param3) if(!cmd.param1 || !cmd.param2 || !cmd.param3)
{ {
if(cmd.param1) free(cmd.param1); /* Release memory */ if(cmd.param1) ast_free(cmd.param1); /* Release memory */
if(cmd.param2) free(cmd.param2); if(cmd.param2) ast_free(cmd.param2);
if(cmd.param3) free(cmd.param3); if(cmd.param3) ast_free(cmd.param3);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
strcpy((char*)cmd.param1, callToken); strcpy((char*)cmd.param1, callToken);
@ -418,14 +418,14 @@ OOStkCmdStat ooHangCall(const char* callToken, OOCallClearReason reason, int q93
if(ooWriteCallStackCommand(call, &cmd) != OO_OK) if(ooWriteCallStackCommand(call, &cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
free(cmd.param3); ast_free(cmd.param3);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
free(cmd.param3); ast_free(cmd.param3);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -473,12 +473,12 @@ OOStkCmdStat ooSendDTMFDigit(const char *callToken, const char* dtmf)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_SENDDIGIT; cmd.type = OO_CMD_SENDDIGIT;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
cmd.param2 = (void*) malloc(strlen(dtmf)+1); cmd.param2 = ast_malloc(strlen(dtmf)+1);
if(!cmd.param1 || !cmd.param2) if(!cmd.param1 || !cmd.param2)
{ {
if(cmd.param1) free(cmd.param1); /* Release memory */ if(cmd.param1) ast_free(cmd.param1); /* Release memory */
if(cmd.param2) free(cmd.param2); if(cmd.param2) ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
strcpy((char*)cmd.param1, callToken); strcpy((char*)cmd.param1, callToken);
@ -488,12 +488,12 @@ OOStkCmdStat ooSendDTMFDigit(const char *callToken, const char* dtmf)
if(ooWriteCallStackCommand(call,&cmd) != OO_OK) if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -521,12 +521,12 @@ OOStkCmdStat ooSetANI(const char *callToken, const char* ani)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_SETANI; cmd.type = OO_CMD_SETANI;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
cmd.param2 = (void*) malloc(strlen(ani)+1); cmd.param2 = ast_malloc(strlen(ani)+1);
if(!cmd.param1 || !cmd.param2) if(!cmd.param1 || !cmd.param2)
{ {
if(cmd.param1) free(cmd.param1); /* Release memory */ if(cmd.param1) ast_free(cmd.param1); /* Release memory */
if(cmd.param2) free(cmd.param2); if(cmd.param2) ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
strcpy((char*)cmd.param1, callToken); strcpy((char*)cmd.param1, callToken);
@ -536,12 +536,12 @@ OOStkCmdStat ooSetANI(const char *callToken, const char* ani)
if(ooWriteCallStackCommand(call,&cmd) != OO_OK) if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }
@ -631,12 +631,12 @@ OOStkCmdStat ooRequestChangeMode(const char *callToken, int isT38Mode)
memset(&cmd, 0, sizeof(OOStackCommand)); memset(&cmd, 0, sizeof(OOStackCommand));
cmd.type = OO_CMD_REQMODE; cmd.type = OO_CMD_REQMODE;
cmd.param1 = (void*) malloc(strlen(callToken)+1); cmd.param1 = ast_malloc(strlen(callToken)+1);
cmd.param2 = (void*) malloc(sizeof(int)); cmd.param2 = ast_malloc(sizeof(int));
if(!cmd.param1 || !cmd.param2) if(!cmd.param1 || !cmd.param2)
{ {
if(cmd.param1) free(cmd.param1); /* Release memory */ ast_free(cmd.param1); /* Release memory */
if(cmd.param2) free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_MEMERR; return OO_STKCMD_MEMERR;
} }
strcpy((char*)cmd.param1, callToken); strcpy((char*)cmd.param1, callToken);
@ -646,12 +646,12 @@ OOStkCmdStat ooRequestChangeMode(const char *callToken, int isT38Mode)
if(ooWriteCallStackCommand(call,&cmd) != OO_OK) if(ooWriteCallStackCommand(call,&cmd) != OO_OK)
{ {
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_WRITEERR; return OO_STKCMD_WRITEERR;
} }
free(cmd.param1); ast_free(cmd.param1);
free(cmd.param2); ast_free(cmd.param2);
return OO_STKCMD_SUCCESS; return OO_STKCMD_SUCCESS;
} }

@ -961,7 +961,7 @@ int ooMonitorCallChannels(OOH323CallData *call)
ast_cond_destroy(&call->gkWait); ast_cond_destroy(&call->gkWait);
pctxt = call->pctxt; pctxt = call->pctxt;
freeContext(pctxt); freeContext(pctxt);
free(pctxt); ast_free(pctxt);
return OO_OK; return OO_OK;
} }

@ -19,6 +19,7 @@
*/ */
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
#include <stdlib.h> #include <stdlib.h>
/* #ifdef HAVE_MALLOC_H /* #ifdef HAVE_MALLOC_H
@ -126,10 +127,10 @@ void printBitStrValue (ASN1UINT numbits, const ASN1OCTET* data)
indent (); indent ();
OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8)); OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8));
#else #else
char* s = (char*)malloc(numbits + 8); char* s = ast_malloc(numbits + 8);
indent (); indent ();
OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8)); OOTRACEDBGB2("%s\n", bitStrToString (numbits, data, s, numbits+8));
free(s); ast_free(s);
#endif #endif
} }
@ -141,10 +142,10 @@ void printOctStrValue (ASN1UINT numocts, const ASN1OCTET* data)
indent (); indent ();
OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz)); OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz));
#else #else
char* s = (char*)malloc(bufsiz); char* s = ast_malloc(bufsiz);
indent (); indent ();
OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz)); OOTRACEDBGB2 ("%s\n", octStrToString (numocts, data, s, bufsiz));
free(s); ast_free(s);
#endif #endif
} }

@ -121,7 +121,7 @@ void* ooh323c_call_thread(void* dummy)
close(mycthread->thePipe[0]); close(mycthread->thePipe[0]);
close(mycthread->thePipe[1]); close(mycthread->thePipe[1]);
free(mycthread); ast_free(mycthread);
ast_module_unref(myself); ast_module_unref(myself);
ast_update_use_count(); ast_update_use_count();
return NULL; return NULL;
@ -155,7 +155,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
ast_module_ref(myself); ast_module_ref(myself);
if ((socketpair(PF_LOCAL, SOCK_STREAM, 0, cur->thePipe)) == -1) { 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); ast_log(LOG_ERROR, "Can't create thread pipe for call %s\n", call->callToken);
free(cur); ast_free(cur);
return -1; return -1;
} }
cur->inUse = TRUE; cur->inUse = TRUE;
@ -173,7 +173,7 @@ int ooh323c_start_call_thread(ooCallData *call) {
ast_mutex_destroy(&cur->lock); ast_mutex_destroy(&cur->lock);
close(cur->thePipe[0]); close(cur->thePipe[0]);
close(cur->thePipe[1]); close(cur->thePipe[1]);
free(cur); ast_free(cur);
return -1; return -1;
} }

@ -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)); jack_port_name(jack_data->output_port));
} }
free((void *) ports); jack_free(ports);
break; 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)); jack_port_name(jack_data->input_port));
} }
free((void *) ports); jack_free(ports);
break; break;
} }

@ -3232,7 +3232,7 @@ static void destroy_queue(void *obj)
ast_string_field_free_memory(q); ast_string_field_free_memory(q);
for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) { for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
if (q->sound_periodicannounce[i]) { if (q->sound_periodicannounce[i]) {
free(q->sound_periodicannounce[i]); ast_free(q->sound_periodicannounce[i]);
} }
} }
ao2_ref(q->members, -1); ao2_ref(q->members, -1);

@ -240,21 +240,21 @@ retry:
done: done:
ast_mutex_unlock(&tds_lock); ast_mutex_unlock(&tds_lock);
free(accountcode_ai); ast_free(accountcode_ai);
free(clidnum_ai); ast_free(clidnum_ai);
free(clid_ai); ast_free(clid_ai);
free(cidani_ai); ast_free(cidani_ai);
free(cidrdnis_ai); ast_free(cidrdnis_ai);
free(ciddnid_ai); ast_free(ciddnid_ai);
free(exten_ai); ast_free(exten_ai);
free(context_ai); ast_free(context_ai);
free(channel_ai); ast_free(channel_ai);
free(app_ai); ast_free(app_ai);
free(appdata_ai); ast_free(appdata_ai);
free(uniqueid_ai); ast_free(uniqueid_ai);
free(linkedid_ai); ast_free(linkedid_ai);
free(userfield_ai); ast_free(userfield_ai);
free(peer_ai); ast_free(peer_ai);
return; return;
} }
@ -317,11 +317,11 @@ static int execute_and_consume(DBPROCESS *dbproc, const char *fmt, ...)
va_end(ap); va_end(ap);
if (dbfcmd(dbproc, buffer) == FAIL) { if (dbfcmd(dbproc, buffer) == FAIL) {
free(buffer); ast_free(buffer);
return 1; return 1;
} }
free(buffer); ast_free(buffer);
if (dbsqlexec(dbproc) == FAIL) { if (dbsqlexec(dbproc) == FAIL) {
return 1; return 1;

@ -860,7 +860,7 @@ static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_a
} else } else
ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc); ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
free(s); ast_free(s);
unref_pvt(pvt); unref_pvt(pvt);

@ -3812,7 +3812,7 @@ static int mgcp_prune_realtime_gateway(struct mgcp_gateway *g)
if (prune) { if (prune) {
ast_mutex_destroy(&s->lock); ast_mutex_destroy(&s->lock);
ast_mutex_destroy(&s->cx_queue_lock); ast_mutex_destroy(&s->cx_queue_lock);
free(s); ast_free(s);
} }
} }
ast_mutex_unlock(&e->lock); 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->lock);
ast_mutex_destroy(&e->rqnt_queue_lock); ast_mutex_destroy(&e->rqnt_queue_lock);
ast_mutex_destroy(&e->cmd_queue_lock); ast_mutex_destroy(&e->cmd_queue_lock);
free(e); ast_free(e);
} }
} }
if (prune) { if (prune) {
@ -3914,7 +3914,7 @@ static void *do_monitor(void *data)
} }
ast_mutex_unlock(&g->msgs_lock); ast_mutex_unlock(&g->msgs_lock);
ast_mutex_destroy(&g->msgs_lock); ast_mutex_destroy(&g->msgs_lock);
free(g); ast_free(g);
} else { } else {
ast_mutex_unlock(&g->msgs_lock); ast_mutex_unlock(&g->msgs_lock);
gprev = g; gprev = g;

@ -8540,16 +8540,16 @@ static void delete_devices(void)
} }
/* Delete all speeddials for this device */ /* Delete all speeddials for this device */
while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) { while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {
free(sd->container); ast_free(sd->container);
free(sd); ast_free(sd);
} }
/* Delete all serviceurls for this device */ /* Delete all serviceurls for this device */
while ((surl = AST_LIST_REMOVE_HEAD(&d->serviceurls, list))) { while ((surl = AST_LIST_REMOVE_HEAD(&d->serviceurls, list))) {
free(surl); ast_free(surl);
} }
/* Delete all addons for this device */ /* Delete all addons for this device */
while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) { while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) {
free(a); ast_free(a);
} }
d = skinny_device_destroy(d); d = skinny_device_destroy(d);
} }
@ -8603,11 +8603,11 @@ int skinny_reload(void)
} }
/* Delete all speeddials for this device */ /* Delete all speeddials for this device */
while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) { while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {
free(sd); ast_free(sd);
} }
/* Delete all addons for this device */ /* Delete all addons for this device */
while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) { while ((a = AST_LIST_REMOVE_HEAD(&d->addons, list))) {
free(a); ast_free(a);
} }
AST_LIST_REMOVE_CURRENT(list); AST_LIST_REMOVE_CURRENT(list);
d = skinny_device_destroy(d); d = skinny_device_destroy(d);

@ -6,9 +6,19 @@ if [ -f addons/mp3/mpg123.h ]; then
echo "need to be downloaded." echo "need to be downloaded."
echo "***" 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 exit 1
fi fi
svn export http://svn.digium.com/svn/thirdparty/mp3/trunk addons/mp3 $@ 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 exit 0

@ -195,7 +195,7 @@ static void curlds_free(void *data)
return; return;
} }
while ((setting = AST_LIST_REMOVE_HEAD(list, list))) { while ((setting = AST_LIST_REMOVE_HEAD(list, list))) {
free(setting); ast_free(setting);
} }
AST_LIST_HEAD_DESTROY(list); AST_LIST_HEAD_DESTROY(list);
} }
@ -393,7 +393,7 @@ yuck:
AST_LIST_TRAVERSE_SAFE_BEGIN(list, cur, list) { AST_LIST_TRAVERSE_SAFE_BEGIN(list, cur, list) {
if (cur->key == new->key) { if (cur->key == new->key) {
AST_LIST_REMOVE_CURRENT(list); AST_LIST_REMOVE_CURRENT(list);
free(cur); ast_free(cur);
break; break;
} }
} }

@ -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_1(void);
void __ast_mm_init_phase_2(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) \ #define calloc(a,b) \
__ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) __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) \ #define ast_calloc(a,b) \
__ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) __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) \ #define ast_calloc_cache(a,b) \
__ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define malloc(a) \
__ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_malloc(a) \ #define ast_malloc(a) \
__ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define free(a) \
__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_free(a) \ #define ast_free(a) \
__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define realloc(a,b) \
__ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_realloc(a,b) \ #define ast_realloc(a,b) \
__ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strdup(a) \
__ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_strdup(a) \ #define ast_strdup(a) \
__ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define strndup(a,b) \
__ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_strndup(a,b) \ #define ast_strndup(a,b) \
__ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) __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...) \ #define ast_asprintf(a, b, c...) \
__ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, 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) \ #define ast_vasprintf(a,b,c) \
__ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)

@ -857,7 +857,7 @@ void ast_jb_conf_default(struct ast_jb_conf *conf)
} }
static void datastore_destroy_cb(void *data) { static void datastore_destroy_cb(void *data) {
ast_free(data); free(data);
ast_debug(1, "JITTERBUFFER datastore destroyed\n"); ast_debug(1, "JITTERBUFFER datastore destroyed\n");
} }

@ -174,7 +174,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
} }
bufsz = ifn.lifn_count * sizeof(struct lifreq); bufsz = ifn.lifn_count * sizeof(struct lifreq);
if (!(buf = malloc(bufsz))) { if (!(buf = ast_malloc(bufsz))) {
close(s); close(s);
return -1; return -1;
} }
@ -187,7 +187,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
ifc.lifc_flags = 0; ifc.lifc_flags = 0;
if (ioctl(s, SIOCGLIFCONF, &ifc) < 0) { if (ioctl(s, SIOCGLIFCONF, &ifc) < 0) {
close(s); close(s);
free(buf); ast_free(buf);
return -1; return -1;
} }
@ -201,7 +201,7 @@ static int get_local_address(struct ast_sockaddr *ourip)
} }
} }
free(buf); ast_free(buf);
#endif /* SOLARIS */ #endif /* SOLARIS */
close(s); close(s);

@ -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) { 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)))) { 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); AST_RWLIST_REMOVE_CURRENT(group_list);
free(gi); ast_free(gi);
break; break;
} }
} }
@ -1900,7 +1900,7 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
if (ast_strlen_zero(group)) { if (ast_strlen_zero(group)) {
/* Enable unsetting the group */ /* Enable unsetting the group */
} else if ((gi = calloc(1, len))) { } else if ((gi = ast_calloc(1, len))) {
gi->chan = chan; gi->chan = chan;
gi->group = (char *) gi + sizeof(*gi); gi->group = (char *) gi + sizeof(*gi);
strcpy(gi->group, group); strcpy(gi->group, group);
@ -2176,9 +2176,9 @@ static void path_lock_destroy(struct path_lock *obj)
close(obj->fd); close(obj->fd);
} }
if (obj->path) { 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) 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; return AST_LOCK_FAILURE;
} }
pl->fd = fd; pl->fd = fd;
pl->path = strdup(path); pl->path = ast_strdup(path);
time(&start); time(&start);
while ( while (

@ -91,6 +91,7 @@
* $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $ * $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 "asterisk.h"
#include <sys/types.h> #include <sys/types.h>

@ -12,6 +12,7 @@
* $FreeBSD: src/bin/expr/expr.y,v 1.16 2000/07/22 10:59:36 se Exp $ * $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 "asterisk.h"
#include <sys/types.h> #include <sys/types.h>

@ -1,3 +1,4 @@
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
#line 2 "ast_expr2f.c" #line 2 "ast_expr2f.c"

@ -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, /* There will only be a single member in the list at this point,
the one we just added. */ the one we just added. */
AST_LIST_REMOVE(&aslist, as, list); AST_LIST_REMOVE(&aslist, as, list);
free(as); ast_free(as);
asthread = AST_PTHREADT_NULL; asthread = AST_PTHREADT_NULL;
res = -1; res = -1;
} else { } else {
@ -313,7 +313,7 @@ int ast_autoservice_stop(struct ast_channel *chan)
} }
ast_channel_unlock(chan); ast_channel_unlock(chan);
free(as); ast_free(as);
return res; return res;
} }

@ -412,17 +412,12 @@ static void filestream_destructor(void *arg)
} }
} }
if (f->filename) ast_free(f->filename);
free(f->filename); ast_free(f->realfilename);
if (f->realfilename)
free(f->realfilename);
if (f->vfs) if (f->vfs)
ast_closestream(f->vfs); ast_closestream(f->vfs);
if (f->write_buffer) { ast_free(f->write_buffer);
ast_free(f->write_buffer); ast_free((void *)f->orig_chan_name);
}
if (f->orig_chan_name)
free((void *) f->orig_chan_name);
ao2_cleanup(f->lastwriteformat); ao2_cleanup(f->lastwriteformat);
ao2_cleanup(f->fr.subclass.format); ao2_cleanup(f->fr.subclass.format);
ast_module_unref(f->fmt->module); ast_module_unref(f->fmt->module);

@ -26,6 +26,7 @@
<support_level>core</support_level> <support_level>core</support_level>
***/ ***/
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@ -255,7 +256,7 @@ ast_hashtab_create
#else #else
if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) { if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) {
#endif #endif
free(ht); ast_free(ht);
return NULL; return NULL;
} }

@ -610,7 +610,7 @@ void ast_module_shutdown(void)
mod->info->unload(); mod->info->unload();
} }
AST_LIST_HEAD_DESTROY(&mod->users); AST_LIST_HEAD_DESTROY(&mod->users);
free(mod); ast_free(mod);
somethingchanged = 1; somethingchanged = 1;
} }
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;

@ -43,6 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/ulaw.h" #include "asterisk/ulaw.h"
#include "asterisk/tdd.h" #include "asterisk/tdd.h"
#include "asterisk/fskmodem.h" #include "asterisk/fskmodem.h"
#include "asterisk/utils.h"
#include "ecdisa.h" #include "ecdisa.h"
struct tdd_state { struct tdd_state {
@ -104,7 +105,7 @@ void tdd_init(void)
struct tdd_state *tdd_new(void) struct tdd_state *tdd_new(void)
{ {
struct tdd_state *tdd; struct tdd_state *tdd;
tdd = calloc(1, sizeof(*tdd)); tdd = ast_calloc(1, sizeof(*tdd));
if (tdd) { if (tdd) {
#ifdef INTEGER_CALLERID #ifdef INTEGER_CALLERID
tdd->fskd.ispb = 176; /* 45.5 baud */ 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 b = 'X';
int res; int res;
int c,x; int c,x;
short *buf = calloc(1, 2 * len + tdd->oldlen); short *buf = ast_calloc(1, 2 * len + tdd->oldlen);
short *obuf = buf; short *obuf = buf;
if (!buf) { if (!buf) {
ast_log(LOG_WARNING, "Out of memory\n"); 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); res = fsk_serial(&tdd->fskd, buf, &mylen, &b);
if (mylen < 0) { if (mylen < 0) {
ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen); ast_log(LOG_ERROR, "fsk_serial made mylen < 0 (%d) (olen was %d)\n", mylen, olen);
free(obuf); ast_free(obuf);
return -1; return -1;
} }
buf += (olen - mylen); buf += (olen - mylen);
if (res < 0) { if (res < 0) {
ast_log(LOG_NOTICE, "fsk_serial failed\n"); ast_log(LOG_NOTICE, "fsk_serial failed\n");
free(obuf); ast_free(obuf);
return -1; return -1;
} }
if (res == 1) { if (res == 1) {
@ -206,7 +207,7 @@ int tdd_feed(struct tdd_state *tdd, unsigned char *ubuf, int len)
tdd->oldlen = mylen * 2; tdd->oldlen = mylen * 2;
} else } else
tdd->oldlen = 0; tdd->oldlen = 0;
free(obuf); ast_free(obuf);
if (res) { if (res) {
tdd->mode = 2; tdd->mode = 2;
/* put it in mode where it /* 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) void tdd_free(struct tdd_state *tdd)
{ {
free(tdd); ast_free(tdd);
} }
static inline float tdd_getcarrier(float *cr, float *ci, int bit) static inline float tdd_getcarrier(float *cr, float *ci, int bit)

@ -260,7 +260,7 @@ static int split_ec(const char *src, char **ext, char ** const ctx, char ** cons
*c++ = '\0'; *c++ = '\0';
*ctx = c; *ctx = c;
if (strchr(c, '@')) { /* two @, not allowed */ if (strchr(c, '@')) { /* two @, not allowed */
free(e); ast_free(e);
return -1; return -1;
} }
} }
@ -311,7 +311,7 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
already_served = lookup_ci(nc, i_name); already_served = lookup_ci(nc, i_name);
if (!already_served && ++which > a->n) if (!already_served && ++which > a->n)
res = strdup(i_name); res = ast_strdup(i_name);
} }
ast_unlock_context(c); ast_unlock_context(c);
} }
@ -328,7 +328,7 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
if (a->n > 0) if (a->n > 0)
return NULL; return NULL;
context = dupline = strdup(s); context = dupline = ast_strdup(s);
if (!dupline) { if (!dupline) {
ast_log(LOG_ERROR, "Out of free memory\n"); ast_log(LOG_ERROR, "Out of free memory\n");
return NULL; return NULL;
@ -337,18 +337,18 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
if (ast_rdlock_contexts()) { if (ast_rdlock_contexts()) {
ast_log(LOG_ERROR, "Failed to lock contexts list\n"); ast_log(LOG_ERROR, "Failed to lock contexts list\n");
free(context); ast_free(context);
return NULL; return NULL;
} }
/* go through all contexts and check if is included ... */ /* go through all contexts and check if is included ... */
while (!res && (c = ast_walk_contexts(c))) while (!res && (c = ast_walk_contexts(c)))
if (lookup_ci(c, context)) /* context is really included, complete "from" command */ if (lookup_ci(c, context)) /* context is really included, complete "from" command */
res = strdup("from"); res = ast_strdup("from");
ast_unlock_contexts(); ast_unlock_contexts();
if (!res) if (!res)
ast_log(LOG_WARNING, "%s not included anywhere\n", context); ast_log(LOG_WARNING, "%s not included anywhere\n", context);
free(context); ast_free(context);
return res; return res;
} else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */ } 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; char *context, *dupline, *from;
const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */ const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
context = dupline = strdup(s); context = dupline = ast_strdup(s);
if (!dupline) { if (!dupline) {
ast_log(LOG_ERROR, "Out of free memory\n"); ast_log(LOG_ERROR, "Out of free memory\n");
return NULL; return NULL;
@ -367,13 +367,13 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
/* fourth word must be 'from' */ /* fourth word must be 'from' */
from = strsep(&dupline, " "); from = strsep(&dupline, " ");
if (!from || strcmp(from, "from")) { if (!from || strcmp(from, "from")) {
free(context); ast_free(context);
return NULL; return NULL;
} }
if (ast_rdlock_contexts()) { if (ast_rdlock_contexts()) {
ast_log(LOG_ERROR, "Failed to lock context list\n"); ast_log(LOG_ERROR, "Failed to lock context list\n");
free(context); ast_free(context);
return NULL; return NULL;
} }
@ -385,10 +385,10 @@ static char *complete_dialplan_remove_include(struct ast_cli_args *a)
continue; continue;
/* walk through all includes and check if it is our context */ /* walk through all includes and check if it is our context */
if (lookup_ci(c, context) && ++which > a->n) if (lookup_ci(c, context) && ++which > a->n)
res = strdup(c_name); res = ast_strdup(c_name);
} }
ast_unlock_contexts(); ast_unlock_contexts();
free(context); ast_free(context);
return res; 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)))) { if ((!strlen(exten)) || (!(strlen(context)))) {
ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n", ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
a->argv[3]); a->argv[3]);
free(exten); ast_free(exten);
return CLI_FAILURE; return CLI_FAILURE;
} }
@ -481,7 +481,7 @@ static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int c
} }
ret = CLI_FAILURE; ret = CLI_FAILURE;
} }
free(exten); ast_free(exten);
return ret; return ret;
} }
@ -593,7 +593,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
ast_unlock_contexts(); ast_unlock_contexts();
error2: error2:
free(exten); ast_free(exten);
} else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */ } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
char *exten = NULL, *context, *cid, *p; char *exten = NULL, *context, *cid, *p;
struct ast_context *c; 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)) ) { while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
snprintf(buffer, sizeof(buffer), "%d", ast_get_extension_priority(priority)); snprintf(buffer, sizeof(buffer), "%d", ast_get_extension_priority(priority));
if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */ if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
ret = strdup(buffer); ret = ast_strdup(buffer);
} }
break; break;
} }
@ -649,7 +649,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
} }
ast_unlock_contexts(); ast_unlock_contexts();
error3: error3:
free(exten); ast_free(exten);
} }
return ret; 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)); ) for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n) 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(); ast_unlock_contexts();
return ret; return ret;
} else if (a->pos == 4) { /* dialplan add include CTX _X_ */ } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
/* always complete as 'into' */ /* 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) */ } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
char *context, *dupline, *into; char *context, *dupline, *into;
const char *s = skip_words(a->line, 3); /* should not fail */ const char *s = skip_words(a->line, 3); /* should not fail */
context = dupline = strdup(s); context = dupline = ast_strdup(s);
if (!dupline) { if (!dupline) {
ast_log(LOG_ERROR, "Out of free memory\n"); 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) && if (partial_match(ast_get_context_name(c), a->word, len) &&
!lookup_ci(c, context) /* not included yet */ && !lookup_ci(c, context) /* not included yet */ &&
++which > a->n) { ++which > a->n) {
ret = strdup(ast_get_context_name(c)); ret = ast_strdup(ast_get_context_name(c));
} }
} }
ast_unlock_contexts(); ast_unlock_contexts();
error3: error3:
free(context); ast_free(context);
return ret; return ret;
} }
@ -1259,7 +1259,7 @@ static char *complete_dialplan_remove_context(struct ast_cli_args *a)
/* walk through all contexts */ /* walk through all contexts */
while ( !res && (c = ast_walk_contexts(c)) ) { while ( !res && (c = ast_walk_contexts(c)) ) {
if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n) { 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(); ast_unlock_contexts();
@ -1272,7 +1272,7 @@ static char *complete_dialplan_add_extension(struct ast_cli_args *a)
int which = 0; int which = 0;
if (a->pos == 4) { /* complete 'into' word ... */ 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 */ } else if (a->pos == 5) { /* complete context */
struct ast_context *c = NULL; struct ast_context *c = NULL;
int len = strlen(a->word); int len = strlen(a->word);
@ -1287,11 +1287,11 @@ static char *complete_dialplan_add_extension(struct ast_cli_args *a)
/* walk through all contexts */ /* walk through all contexts */
while ( !res && (c = ast_walk_contexts(c)) ) while ( !res && (c = ast_walk_contexts(c)) )
if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n) 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(); ast_unlock_contexts();
return res; return res;
} else if (a->pos == 6) { } else if (a->pos == 6) {
return a->n == 0 ? strdup("replace") : NULL; return a->n == 0 ? ast_strdup("replace") : NULL;
} }
return 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) static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
{ {
if (a->pos == 4) if (a->pos == 4)
return a->n == 0 ? strdup("into") : NULL; return a->n == 0 ? ast_strdup("into") : NULL;
else if (a->pos == 5) { else if (a->pos == 5) {
struct ast_context *c; struct ast_context *c;
int which = 0; int which = 0;
@ -1369,7 +1369,7 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
s = skip_words(a->line, 3); s = skip_words(a->line, 3);
if (s == NULL) if (s == NULL)
return NULL; return NULL;
dupline = strdup(s); dupline = ast_strdup(s);
if (!dupline) { if (!dupline) {
ast_log(LOG_ERROR, "Malloc failure\n"); ast_log(LOG_ERROR, "Malloc failure\n");
return NULL; return NULL;
@ -1389,10 +1389,10 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
if (ignorepat) /* there must be one, right ? */ if (ignorepat) /* there must be one, right ? */
found = lookup_c_ip(c, ignorepat); found = lookup_c_ip(c, ignorepat);
if (!found && ++which > a->n) 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(); ast_unlock_contexts();
return ret; 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)); found = lookup_c_ip(cw, ast_get_ignorepat_name(ip));
} }
if (!found) if (!found)
ret = strdup(ast_get_ignorepat_name(ip)); ret = ast_strdup(ast_get_ignorepat_name(ip));
} }
} }
ast_unlock_context(c); ast_unlock_context(c);
@ -1486,12 +1486,12 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
ast_unlock_contexts(); ast_unlock_contexts();
return ret; return ret;
} else if (a->pos == 4) { } 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 */ } else if (a->pos == 5) { /* XXX check this */
char *dupline, *duplinet, *ignorepat; char *dupline, *duplinet, *ignorepat;
int len = strlen(a->word); int len = strlen(a->word);
dupline = strdup(a->line); dupline = ast_strdup(a->line);
if (!dupline) { if (!dupline) {
ast_log(LOG_WARNING, "Out of free memory\n"); ast_log(LOG_WARNING, "Out of free memory\n");
return NULL; return NULL;
@ -1503,13 +1503,13 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
ignorepat = strsep(&duplinet, " "); ignorepat = strsep(&duplinet, " ");
if (!ignorepat) { if (!ignorepat) {
free(dupline); ast_free(dupline);
return NULL; return NULL;
} }
if (ast_rdlock_contexts()) { if (ast_rdlock_contexts()) {
ast_log(LOG_WARNING, "Failed to lock contexts list\n"); ast_log(LOG_WARNING, "Failed to lock contexts list\n");
free(dupline); ast_free(dupline);
return NULL; 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)) if (!partial_match(ast_get_context_name(c), a->word, len))
continue; continue;
if (lookup_c_ip(c, ignorepat) && ++which > a->n) 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_context(c);
} }
ast_unlock_contexts(); ast_unlock_contexts();
free(dupline); ast_free(dupline);
return NULL; return NULL;
} }

@ -68,6 +68,7 @@
%option bison-locations %option bison-locations
%{ %{
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")

@ -99,6 +99,7 @@
* *
*/ */
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")

@ -22,6 +22,7 @@
* *
*/ */
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")

@ -1,3 +1,4 @@
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
#line 2 "ael_lex.c" #line 2 "ael_lex.c"

@ -27,6 +27,7 @@
<support_level>extended</support_level> <support_level>extended</support_level>
***/ ***/
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ASTERISK_FILE_VERSION(__FILE__, "$Revision$")

@ -124,7 +124,7 @@ static struct ldap_table_config *table_config_new(const char *table_name)
if (table_name) { if (table_name) {
if (!(p->table_name = ast_strdup(table_name))) { if (!(p->table_name = ast_strdup(table_name))) {
free(p); ast_free(p);
return NULL; return NULL;
} }
} }
@ -238,7 +238,7 @@ static void table_configs_free(void)
if (c->attributes) { if (c->attributes) {
ast_variables_destroy(c->attributes); ast_variables_destroy(c->attributes);
} }
free(c); ast_free(c);
} }
base_table_config = NULL; base_table_config = NULL;
@ -516,14 +516,14 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
is_delimited = 0; is_delimited = 0;
pos = 0; pos = 0;
} }
free(delim_value); ast_free(delim_value);
delim_value = NULL; delim_value = NULL;
ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i); ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
} else { } else {
/* not delimited */ /* not delimited */
if (delim_value) { if (delim_value) {
free(delim_value); ast_free(delim_value);
delim_value = NULL; delim_value = NULL;
} }
ast_debug(2, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, valptr); 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++; p++;
} }
free(vars); ast_free(vars);
} }
return var; return var;
} }
@ -1066,7 +1066,7 @@ static struct ast_config *realtime_multi_ldap(const char *basedn,
p++; p++;
} }
} }
free(vars); ast_free(vars);
} }
return cfg; 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_log(LOG_WARNING, "Query: %s\n", ast_str_buffer(filter));
ast_mutex_unlock(&ldap_lock); ast_mutex_unlock(&ldap_lock);
free(filter); ast_free(filter);
free(clean_basedn); ast_free(clean_basedn);
ldap_msgfree(ldap_result_msg); ldap_msgfree(ldap_result_msg);
ldap_mods_free(ldap_mods, 0); ldap_mods_free(ldap_mods, 0);
return -1; return -1;

@ -272,7 +272,7 @@ static int profile_cmp_fn(void *obj, void *arg, int flags)
static void delete_file(struct phoneprov_file *file) static void delete_file(struct phoneprov_file *file)
{ {
ast_string_field_free_memory(file); ast_string_field_free_memory(file);
free(file); ast_free(file);
} }
static void profile_destructor(void *obj) static void profile_destructor(void *obj)
@ -340,7 +340,7 @@ static int load_file(const char *filename, char **ret)
return -2; return -2;
if (len != fread(*ret, sizeof(char), len, f)) { if (len != fread(*ret, sizeof(char), len, f)) {
free(*ret); ast_free(*ret);
*ret = NULL; *ret = NULL;
return -3; return -3;
} }

@ -340,7 +340,7 @@ static int cops_getmsg (int sfd, struct copsmsg *recmsg)
recmsg->length = ntohl(*((uint32_t *) (buf + 4))); recmsg->length = ntohl(*((uint32_t *) (buf + 4)));
/* Eg KA msg*/ /* Eg KA msg*/
if (recmsg->clienttype != 0x8008 ) { 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; return -1;
} }
lent = recv(sfd, recmsg->msg, recmsg->length - COPS_HEADER_SIZE, MSG_DONTWAIT); 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) { while (len < recmsg->length) {
if (len == COPS_HEADER_SIZE) { if (len == COPS_HEADER_SIZE) {
/* 1st round */ /* 1st round */
if (!(recmsg->object = malloc(sizeof(struct pktcobj)))) { if (!(recmsg->object = ast_malloc(sizeof(struct pktcobj)))) {
return -1; return -1;
} }
pobject = recmsg->object; pobject = recmsg->object;
} else { } else {
if (!(pobject->next = malloc(sizeof(struct pktcobj)))) { if (!(pobject->next = ast_malloc(sizeof(struct pktcobj)))) {
return -1; return -1;
} }
pobject = pobject->next; pobject = pobject->next;
@ -373,7 +373,7 @@ static int cops_getmsg (int sfd, struct copsmsg *recmsg)
pobject->length = ntohs(*ubuf); pobject->length = ntohs(*ubuf);
pobject->cnum = *(buf + 2); pobject->cnum = *(buf + 2);
pobject->ctype = *(buf + 3); 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; return -1;
} }
lent = recv(sfd, pobject->contents, pobject->length - COPS_OBJECT_HEADER_SIZE, MSG_DONTWAIT); 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"); ast_log(LOG_WARNING, "COPS: invalid msg size!!!\n");
return -1; return -1;
} }
if (!(buf = malloc((size_t) sendmsg->length))) { if (!(buf = ast_malloc((size_t) sendmsg->length))) {
return -1; return -1;
} }
*buf = sendmsg->verflag ; *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); 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) { if (sendmsg->length < bufpos + pobject->length) {
ast_log(LOG_WARNING, "COPS: Invalid msg size len: %u objectlen: %i\n", sendmsg->length, 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; return -1;
} }
*(uint16_t *) (buf + bufpos) = htons(pobject->length); *(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; *(buf + bufpos + 3) = pobject->ctype;
if (sendmsg->length < pobject->length + bufpos) { 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); 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; return -1;
} }
memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4); memcpy((buf + bufpos + 4), pobject->contents, pobject->length - 4);
@ -444,18 +444,18 @@ static int cops_sendmsg (int sfd, struct copsmsg * sendmsg)
#endif #endif
if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) { if (send(sfd, buf, sendmsg->length, SENDFLAGS) == -1) {
ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno); ast_log(LOG_WARNING, "COPS: Send failed errno=%i\n", errno);
free(buf); ast_free(buf);
return -2; return -2;
} }
#undef SENDFLAGS #undef SENDFLAGS
free(buf); ast_free(buf);
return 0; return 0;
} }
static void cops_freemsg(struct copsmsg *p) static void cops_freemsg(struct copsmsg *p)
{ {
struct pktcobj *pnext; struct pktcobj *pnext;
free(p->msg); ast_free(p->msg);
p->msg = NULL; p->msg = NULL;
while (p->object != NULL) { while (p->object != NULL) {
pnext = p->object->next; 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); gate->in_transaction = time(NULL);
if (!(gateset = malloc(sizeof(struct copsmsg)))) { if (!(gateset = ast_malloc(sizeof(struct copsmsg)))) {
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
gateset->msg = 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 */ gateset->clienttype = 0x8008; /* =PacketCable */
/* Handle object */ /* Handle object */
gateset->object = malloc(sizeof(struct pktcobj)); gateset->object = ast_malloc(sizeof(struct pktcobj));
if (!gateset->object) { if (!gateset->object) {
cops_freemsg(gateset); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4; gateset->object->length = COPS_OBJECT_HEADER_SIZE + 4;
gateset->object->cnum = 1; /* Handle */ gateset->object->cnum = 1; /* Handle */
gateset->object->ctype = 1; /* client */ 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); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
*((uint32_t *) gateset->object->contents) = htonl(cmts->handle); *((uint32_t *) gateset->object->contents) = htonl(cmts->handle);
/* Context Object */ /* Context Object */
if (!(gateset->object->next = malloc(sizeof(struct pktcobj)))) { if (!(gateset->object->next = ast_malloc(sizeof(struct pktcobj)))) {
cops_freemsg(gateset); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4; gateset->object->next->length = COPS_OBJECT_HEADER_SIZE + 4;
gateset->object->next->cnum = 2; /* Context */ gateset->object->next->cnum = 2; /* Context */
gateset->object->next->ctype = 1; /* 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); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
*((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */ *((uint32_t *) gateset->object->next->contents) = htonl(0x00080000); /* R-Type = 8 configuration request, M-Type = 0 */
/* Decision Object: Flags */ /* 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); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4; gateset->object->next->next->length = COPS_OBJECT_HEADER_SIZE + 4;
gateset->object->next->next->cnum = 6; /* Decision */ gateset->object->next->next->cnum = 6; /* Decision */
gateset->object->next->next->ctype = 1; /* Flags */ 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); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
*((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */ *((uint32_t *) gateset->object->next->next->contents) = htonl(0x00010001); /* Install, Trigger Error */
/* Decision Object: Data */ /* 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); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; 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->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->cnum = 6; /* Decision */
gateset->object->next->next->next->ctype = 4; /* Decision Data */ 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) { if (!gateset->object->next->next->next->contents) {
cops_freemsg(gateset); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return NULL; return NULL;
} }
gateset->object->next->next->next->next = 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_sendmsg(cmts->sfd, gateset);
cops_freemsg(gateset); cops_freemsg(gateset);
free(gateset); ast_free(gateset);
return gate; return gate;
} }
@ -929,11 +929,11 @@ static void *do_pktccops(void *data)
sendmsg->opcode = 7; /* Client Accept */ sendmsg->opcode = 7; /* Client Accept */
sendmsg->clienttype = 0x8008; /* =PacketCable */ sendmsg->clienttype = 0x8008; /* =PacketCable */
sendmsg->length = COPS_HEADER_SIZE + COPS_OBJECT_HEADER_SIZE + 4; 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->length = 4 + COPS_OBJECT_HEADER_SIZE;
sendmsg->object->cnum = 10; /* keppalive timer*/ sendmsg->object->cnum = 10; /* keppalive timer*/
sendmsg->object->ctype = 1; 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); *((uint32_t *) sendmsg->object->contents) = htonl(cmts->keepalive & 0x0000ffff);
sendmsg->object->next = NULL; sendmsg->object->next = NULL;
cops_sendmsg(cmts->sfd, sendmsg); cops_sendmsg(cmts->sfd, sendmsg);
@ -980,7 +980,7 @@ static void *do_pktccops(void *data)
close(cmts->sfd); close(cmts->sfd);
} }
AST_LIST_REMOVE_CURRENT(list); AST_LIST_REMOVE_CURRENT(list);
free(cmts); ast_free(cmts);
} }
} }
AST_LIST_TRAVERSE_SAFE_END; AST_LIST_TRAVERSE_SAFE_END;
@ -1442,13 +1442,13 @@ static void pktccops_unregister_cmtses(void)
if (cmts->sfd > 0) { if (cmts->sfd > 0) {
close(cmts->sfd); close(cmts->sfd);
} }
free(cmts); ast_free(cmts);
} }
AST_LIST_UNLOCK(&cmts_list); AST_LIST_UNLOCK(&cmts_list);
AST_LIST_LOCK(&gate_list); AST_LIST_LOCK(&gate_list);
while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) { while ((gate = AST_LIST_REMOVE_HEAD(&gate_list, list))) {
free(gate); ast_free(gate);
} }
AST_LIST_UNLOCK(&gate_list); AST_LIST_UNLOCK(&gate_list);
} }
@ -1458,7 +1458,7 @@ static void pktccops_unregister_ippools(void)
struct cops_ippool *ippool; struct cops_ippool *ippool;
AST_LIST_LOCK(&ippool_list); AST_LIST_LOCK(&ippool_list);
while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) { while ((ippool = AST_LIST_REMOVE_HEAD(&ippool_list, list))) {
free(ippool); ast_free(ippool);
} }
AST_LIST_UNLOCK(&ippool_list); AST_LIST_UNLOCK(&ippool_list);
} }

@ -4914,7 +4914,7 @@ static void ast_rtp_stop(struct ast_rtp_instance *instance)
if (rtp->red) { if (rtp->red) {
AST_SCHED_DEL(rtp->sched, rtp->red->schedid); AST_SCHED_DEL(rtp->sched, rtp->red->schedid);
free(rtp->red); ast_free(rtp->red);
rtp->red = NULL; rtp->red = NULL;
} }

@ -246,7 +246,7 @@ static void smdi_interface_destroy(void *obj)
ast_mutex_destroy(&iface->mwi_q_lock); ast_mutex_destroy(&iface->mwi_q_lock);
ast_cond_destroy(&iface->mwi_q_cond); ast_cond_destroy(&iface->mwi_q_cond);
free(iface); ast_free(iface);
ast_module_unref(ast_module_info->self); 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); ast_string_field_free_memory(mm);
ao2_ref(mm->iface, -1); ao2_ref(mm->iface, -1);
free(mm); ast_free(mm);
} }
static void destroy_all_mailbox_mappings(void) 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->iface);
ao2_cleanup(smd->md_msg); ao2_cleanup(smd->md_msg);
free(smd); ast_free(smd);
} }
static const struct ast_datastore_info smdi_msg_datastore_info = { static const struct ast_datastore_info smdi_msg_datastore_info = {

@ -106,10 +106,10 @@ static void destroy_test_container(struct test_container *x)
struct test1 *t1; struct test1 *t1;
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&x->entries, t1, list) { AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(&x->entries, t1, list) {
AST_DLLIST_REMOVE_CURRENT(list); AST_DLLIST_REMOVE_CURRENT(list);
free(t1); ast_free(t1);
} }
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END; AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
free(x); ast_free(x);
} }
/* Macros to test: /* Macros to test:
@ -337,7 +337,7 @@ static void dll_tests(void)
if (e == b) { if (e == b) {
AST_DLLIST_REMOVE_CURRENT(list); /* C A */ AST_DLLIST_REMOVE_CURRENT(list); /* C A */
free(b); ast_free(b);
print_list(tc, "C <=> A"); print_list(tc, "C <=> A");
} }
if (e == a) { if (e == a) {

@ -43,6 +43,7 @@
<support_level>extended</support_level> <support_level>extended</support_level>
***/ ***/
#define WRAP_LIBC_MALLOC
#include "asterisk.h" #include "asterisk.h"
#undef DEBUG_THREADS #undef DEBUG_THREADS

Loading…
Cancel
Save