mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
- conversions to allocation wrappers
- replace malloc/memset with ast_calloc - replace malloc/ast_copy_string with ast_strdup (based on patch from issue #6299) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8410 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -215,13 +215,10 @@ static struct ast_key *try_load_key (char *dir, char *fname, int ifd, int ofd, i
|
||||
/* Make fname just be the normal name now */
|
||||
*c = '\0';
|
||||
if (!key) {
|
||||
key = (struct ast_key *)malloc(sizeof(struct ast_key));
|
||||
if (!key) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
if (!(key = ast_calloc(1, sizeof(*key)))) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
memset(key, 0, sizeof(struct ast_key));
|
||||
}
|
||||
/* At this point we have a key structure (old or new). Time to
|
||||
fill it with what we know */
|
||||
|
@@ -264,12 +264,9 @@ int ast_park_call(struct ast_channel *chan, struct ast_channel *peer, int timeou
|
||||
char exten[AST_MAX_EXTENSION];
|
||||
struct ast_context *con;
|
||||
|
||||
pu = malloc(sizeof(struct parkeduser));
|
||||
if (!pu) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
if (!(pu = ast_calloc(1, sizeof(*pu)))) {
|
||||
return -1;
|
||||
}
|
||||
memset(pu, 0, sizeof(struct parkeduser));
|
||||
ast_mutex_lock(&parking_lock);
|
||||
parking_range = parking_stop - parking_start+1;
|
||||
for (i = 0; i < parking_range; i++) {
|
||||
@@ -386,8 +383,7 @@ int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int
|
||||
struct ast_frame *f;
|
||||
|
||||
/* Make a new, fake channel that we'll use to masquerade in the real one */
|
||||
chan = ast_channel_alloc(0);
|
||||
if (chan) {
|
||||
if ((chan = ast_channel_alloc(0))) {
|
||||
/* Let us keep track of the channel name */
|
||||
snprintf(chan->name, sizeof (chan->name), "Parked/%s",rchan->name);
|
||||
|
||||
@@ -786,9 +782,7 @@ static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, st
|
||||
ast_clear_flag(newchan, AST_FLAGS_ALL);
|
||||
newchan->_softhangup = 0;
|
||||
|
||||
tobj = malloc(sizeof(struct ast_bridge_thread_obj));
|
||||
if (tobj) {
|
||||
memset(tobj,0,sizeof(struct ast_bridge_thread_obj));
|
||||
if ((tobj = ast_calloc(1, sizeof(*tobj)))) {
|
||||
tobj->chan = xferchan;
|
||||
tobj->peer = newchan;
|
||||
tobj->bconfig = *config;
|
||||
@@ -800,7 +794,6 @@ static int builtin_atxfer(struct ast_channel *chan, struct ast_channel *peer, st
|
||||
}
|
||||
ast_bridge_call_thread_launch(tobj);
|
||||
} else {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
ast_hangup(xferchan);
|
||||
ast_hangup(newchan);
|
||||
}
|
||||
@@ -1214,10 +1207,7 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call
|
||||
*outstate = state;
|
||||
|
||||
if (chan && res <= 0) {
|
||||
if (!chan->cdr) {
|
||||
chan->cdr = ast_cdr_alloc();
|
||||
}
|
||||
if (chan->cdr) {
|
||||
if (chan->cdr || (chan->cdr = ast_cdr_alloc())) {
|
||||
char tmp[256];
|
||||
ast_cdr_init(chan->cdr, chan);
|
||||
snprintf(tmp, 256, "%s/%s", type, (char *)data);
|
||||
@@ -2088,21 +2078,19 @@ static int load_config(void)
|
||||
}
|
||||
|
||||
{
|
||||
struct ast_call_feature *feature=find_feature(var->name);
|
||||
struct ast_call_feature *feature;
|
||||
int mallocd = 0;
|
||||
|
||||
if (!feature) {
|
||||
feature=malloc(sizeof(struct ast_call_feature));
|
||||
if (!(feature = find_feature(var->name))) {
|
||||
mallocd = 1;
|
||||
}
|
||||
if (!feature) {
|
||||
ast_log(LOG_NOTICE, "Malloc failed at feature mapping\n");
|
||||
|
||||
if (!(feature = ast_calloc(1, sizeof(*feature)))) {
|
||||
free(tmp_val);
|
||||
var = var->next;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
memset(feature,0,sizeof(struct ast_call_feature));
|
||||
ast_copy_string(feature->sname,var->name,FEATURE_SNAME_LEN);
|
||||
ast_copy_string(feature->app,app,FEATURE_APP_LEN);
|
||||
ast_copy_string(feature->exten, exten,FEATURE_EXTEN_LEN);
|
||||
|
@@ -47,7 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "asterisk/module.h"
|
||||
#include "asterisk/translate.h"
|
||||
#include "asterisk/indications.h"
|
||||
|
||||
#include "asterisk/utils.h"
|
||||
|
||||
/* Globals */
|
||||
static const char dtext[] = "Indications Configuration";
|
||||
@@ -95,12 +95,9 @@ static int handle_add_indication(int fd, int argc, char *argv[])
|
||||
/* country does not exist, create it */
|
||||
ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n",argv[2]);
|
||||
|
||||
tz = malloc(sizeof(struct tone_zone));
|
||||
if (!tz) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
if (!(tz = ast_calloc(1, sizeof(*tz)))) {
|
||||
return -1;
|
||||
}
|
||||
memset(tz,0,sizeof(struct tone_zone));
|
||||
ast_copy_string(tz->country,argv[2],sizeof(tz->country));
|
||||
if (ast_register_indication_country(tz)) {
|
||||
ast_log(LOG_WARNING, "Unable to register new country\n");
|
||||
@@ -258,13 +255,10 @@ static int ind_load_module(void)
|
||||
cxt = ast_category_browse(cfg, cxt);
|
||||
continue;
|
||||
}
|
||||
tones = malloc(sizeof(struct tone_zone));
|
||||
if (!tones) {
|
||||
ast_log(LOG_WARNING,"Out of memory\n");
|
||||
if (!(tones = ast_calloc(1, sizeof(*tones)))) {
|
||||
ast_config_destroy(cfg);
|
||||
return -1;
|
||||
}
|
||||
memset(tones,0,sizeof(struct tone_zone));
|
||||
ast_copy_string(tones->country,cxt,sizeof(tones->country));
|
||||
|
||||
v = ast_variable_browse(cfg, cxt);
|
||||
@@ -282,9 +276,7 @@ static int ind_load_module(void)
|
||||
ring = strsep(&c,",");
|
||||
continue;
|
||||
}
|
||||
tmp = realloc(tones->ringcadence,(tones->nrringcadence+1)*sizeof(int));
|
||||
if (!tmp) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) {
|
||||
ast_config_destroy(cfg);
|
||||
return -1;
|
||||
}
|
||||
@@ -299,13 +291,11 @@ static int ind_load_module(void)
|
||||
c = countries;
|
||||
country = strsep(&c,",");
|
||||
while (country) {
|
||||
struct tone_zone* azone = malloc(sizeof(struct tone_zone));
|
||||
if (!azone) {
|
||||
ast_log(LOG_WARNING,"Out of memory\n");
|
||||
struct tone_zone* azone;
|
||||
if (!(azone = ast_calloc(1, sizeof(*azone)))) {
|
||||
ast_config_destroy(cfg);
|
||||
return -1;
|
||||
}
|
||||
memset(azone,0,sizeof(struct tone_zone));
|
||||
ast_copy_string(azone->country, country, sizeof(azone->country));
|
||||
ast_copy_string(azone->alias, cxt, sizeof(azone->alias));
|
||||
if (ast_register_indication_country(azone)) {
|
||||
@@ -326,9 +316,7 @@ static int ind_load_module(void)
|
||||
}
|
||||
}
|
||||
/* not there, add it to the back */
|
||||
ts = malloc(sizeof(struct tone_zone_sound));
|
||||
if (!ts) {
|
||||
ast_log(LOG_WARNING, "Out of memory\n");
|
||||
if (!(ts = ast_malloc(sizeof(*ts)))) {
|
||||
ast_config_destroy(cfg);
|
||||
return -1;
|
||||
}
|
||||
|
@@ -150,12 +150,10 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
|
||||
}
|
||||
}
|
||||
|
||||
monitor = malloc(sizeof(struct ast_channel_monitor));
|
||||
if (!monitor) {
|
||||
if (!(monitor = ast_calloc(1, sizeof(*monitor)))) {
|
||||
UNLOCK_IF_NEEDED(&chan->lock, need_lock);
|
||||
return -1;
|
||||
}
|
||||
memset(monitor, 0, sizeof(struct ast_channel_monitor));
|
||||
|
||||
/* Determine file names */
|
||||
if (!ast_strlen_zero(fname_base)) {
|
||||
@@ -416,8 +414,8 @@ static int start_monitor_exec(struct ast_channel *chan, void *data)
|
||||
if (urlprefix) {
|
||||
snprintf(tmp,sizeof(tmp) - 1,"%s/%s.%s",urlprefix,fname_base,
|
||||
((strcmp(format,"gsm")) ? "wav" : "gsm"));
|
||||
if (!chan->cdr)
|
||||
chan->cdr = ast_cdr_alloc();
|
||||
if (!chan->cdr && !(chan->cdr = ast_cdr_alloc()))
|
||||
return -1;
|
||||
ast_cdr_setuserfield(chan, tmp);
|
||||
}
|
||||
if (waitforbridge) {
|
||||
@@ -492,16 +490,14 @@ static int start_monitor_action(struct mansession *s, struct message *m)
|
||||
|
||||
if (ast_strlen_zero(fname)) {
|
||||
/* No filename base specified, default to channel name as per CLI */
|
||||
fname = malloc (FILENAME_MAX);
|
||||
if (!fname) {
|
||||
if (!(fname = ast_strdup(c->name))) {
|
||||
astman_send_error(s, m, "Could not start monitoring channel");
|
||||
ast_mutex_unlock(&c->lock);
|
||||
return 0;
|
||||
}
|
||||
memset(fname, 0, FILENAME_MAX);
|
||||
ast_copy_string(fname, c->name, FILENAME_MAX);
|
||||
/* Channels have the format technology/channel_name - have to replace that / */
|
||||
if ((d=strchr(fname, '/'))) *d='-';
|
||||
if ((d = strchr(fname, '/')))
|
||||
*d = '-';
|
||||
}
|
||||
|
||||
if (ast_monitor_start(c, format, fname, 1)) {
|
||||
|
@@ -279,18 +279,17 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params)
|
||||
{
|
||||
struct moh_files_state *state;
|
||||
struct mohclass *class = params;
|
||||
int allocated = 0;
|
||||
|
||||
if (!chan->music_state && (state = malloc(sizeof(struct moh_files_state)))) {
|
||||
if (!chan->music_state && (state = ast_calloc(1, sizeof(*state)))) {
|
||||
chan->music_state = state;
|
||||
allocated = 1;
|
||||
state->class = class;
|
||||
} else
|
||||
state = chan->music_state;
|
||||
|
||||
if (state) {
|
||||
if (allocated || state->class != class) {
|
||||
if (state->class != class) {
|
||||
/* initialize */
|
||||
memset(state, 0, sizeof(struct moh_files_state));
|
||||
memset(state, 0, sizeof(*state));
|
||||
state->class = class;
|
||||
}
|
||||
|
||||
@@ -612,10 +611,8 @@ static struct mohdata *mohalloc(struct mohclass *cl)
|
||||
{
|
||||
struct mohdata *moh;
|
||||
long flags;
|
||||
moh = malloc(sizeof(struct mohdata));
|
||||
if (!moh)
|
||||
if (!(moh = ast_calloc(1, sizeof(*moh))))
|
||||
return NULL;
|
||||
memset(moh, 0, sizeof(struct mohdata));
|
||||
if (pipe(moh->pipe)) {
|
||||
ast_log(LOG_WARNING, "Failed to create pipe: %s\n", strerror(errno));
|
||||
free(moh);
|
||||
@@ -669,8 +666,7 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
|
||||
struct mohdata *res;
|
||||
struct mohclass *class = params;
|
||||
|
||||
res = mohalloc(class);
|
||||
if (res) {
|
||||
if ((res = mohalloc(class))) {
|
||||
res->origwfmt = chan->writeformat;
|
||||
if (ast_set_write_format(chan, class->format)) {
|
||||
ast_log(LOG_WARNING, "Unable to set channel '%s' to format '%s'\n", chan->name, ast_codec2str(class->format));
|
||||
@@ -907,13 +903,7 @@ static struct mohclass *moh_class_malloc(void)
|
||||
{
|
||||
struct mohclass *class;
|
||||
|
||||
class = malloc(sizeof(struct mohclass));
|
||||
|
||||
if (!class)
|
||||
return NULL;
|
||||
|
||||
memset(class, 0, sizeof(struct mohclass));
|
||||
|
||||
if ((class = ast_calloc(1, sizeof(*class))))
|
||||
class->format = AST_FORMAT_SLINEAR;
|
||||
|
||||
return class;
|
||||
@@ -938,9 +928,7 @@ static int load_moh_classes(int reload)
|
||||
cat = ast_category_browse(cfg, NULL);
|
||||
for (; cat; cat = ast_category_browse(cfg, cat)) {
|
||||
if (strcasecmp(cat, "classes") && strcasecmp(cat, "moh_files")) {
|
||||
class = moh_class_malloc();
|
||||
if (!class) {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
if (!(class = moh_class_malloc())) {
|
||||
break;
|
||||
}
|
||||
ast_copy_string(class->name, cat, sizeof(class->name));
|
||||
@@ -1006,9 +994,7 @@ static int load_moh_classes(int reload)
|
||||
if (args)
|
||||
*args++ = '\0';
|
||||
if (!(get_mohbyname(var->name))) {
|
||||
class = moh_class_malloc();
|
||||
if (!class) {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
if (!(class = moh_class_malloc())) {
|
||||
return numclasses;
|
||||
}
|
||||
|
||||
@@ -1034,9 +1020,7 @@ static int load_moh_classes(int reload)
|
||||
args = strchr(var->value, ',');
|
||||
if (args)
|
||||
*args++ = '\0';
|
||||
class = moh_class_malloc();
|
||||
if (!class) {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
if (!(class = moh_class_malloc())) {
|
||||
return numclasses;
|
||||
}
|
||||
|
||||
|
@@ -124,12 +124,9 @@ static int osp_build(struct ast_config *cfg, char *cat)
|
||||
ast_mutex_unlock(&osplock);
|
||||
if (!osp) {
|
||||
mallocd = 1;
|
||||
osp = malloc(sizeof(struct osp_provider));
|
||||
if (!osp) {
|
||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||
if (!(osp = ast_calloc(1, sizeof(*osp)))) {
|
||||
return -1;
|
||||
}
|
||||
memset(osp, 0, sizeof(struct osp_provider));
|
||||
osp->handle = -1;
|
||||
}
|
||||
ast_copy_string(osp->name, cat, sizeof(osp->name));
|
||||
|
Reference in New Issue
Block a user