Skip to content

Commit

Permalink
core: Don't allow free to mean ast_free (and malloc, etc..).
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wdoekes committed Sep 26, 2014
1 parent b8c1130 commit 37179a2
Show file tree
Hide file tree
Showing 44 changed files with 375 additions and 341 deletions.
4 changes: 2 additions & 2 deletions addons/app_mysql.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
110 changes: 55 additions & 55 deletions addons/chan_ooh323.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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); */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand All @@ -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"))) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2273,7 +2273,7 @@ int onCallCleared(ooCallData *call)
}
ast_mutex_unlock(&userl.lock);
free(user);
ast_free(user);
}
if (gH323Debug)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 !!! */
Expand Down Expand Up @@ -4181,21 +4181,21 @@ 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--;
ast_mutex_unlock(&prev->rtpmask->lock);
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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

}
Expand Down
5 changes: 3 additions & 2 deletions addons/ooh323c/src/context.c
Expand Up @@ -15,6 +15,7 @@
*****************************************************************************/
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"

#include "ooasn1.h"
#include <stdlib.h>
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions addons/ooh323c/src/errmgmt.c
Expand Up @@ -18,6 +18,7 @@

#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include <stdlib.h>
#include "ooasn1.h"

Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 37179a2

Please sign in to comment.