More memory wrapper cleanup. #6224

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8045 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
BJ Weschke
2006-01-13 03:34:31 +00:00
parent 8637b23569
commit f6c5e65266
6 changed files with 22 additions and 24 deletions

View File

@@ -86,7 +86,10 @@ static char *socket_receive_file_to_buff(int fd,int *size)
char c; char c;
bufflen = 1024; bufflen = 1024;
buff = (char *)malloc(bufflen); if (!(buff = ast_malloc(bufflen)))
{
/* TODO: Handle memory allocation failure */
}
*size=0; *size=0;
for (k=0; file_stuff_key[k] != '\0';) for (k=0; file_stuff_key[k] != '\0';)
@@ -96,7 +99,10 @@ static char *socket_receive_file_to_buff(int fd,int *size)
if ((*size)+k+1 >= bufflen) if ((*size)+k+1 >= bufflen)
{ /* +1 so you can add a NULL if you want */ { /* +1 so you can add a NULL if you want */
bufflen += bufflen/4; bufflen += bufflen/4;
buff = (char *)realloc(buff,bufflen); if (!(buff = ast_realloc(buff, bufflen)))
{
/* TODO: Handle memory allocation failure */
}
} }
if (file_stuff_key[k] == c) if (file_stuff_key[k] == c)
k++; k++;

View File

@@ -474,8 +474,7 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
if (!cnf && (make || dynamic)) { if (!cnf && (make || dynamic)) {
/* Make a new one */ /* Make a new one */
cnf = calloc(1, sizeof(*cnf)); if ((cnf = ast_calloc(1, sizeof(*cnf)))) {
if (cnf) {
ast_mutex_init(&cnf->playlock); ast_mutex_init(&cnf->playlock);
ast_mutex_init(&cnf->listenlock); ast_mutex_init(&cnf->listenlock);
ast_copy_string(cnf->confno, confno, sizeof(cnf->confno)); ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
@@ -535,8 +534,7 @@ static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin
ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno); ast_verbose(VERBOSE_PREFIX_3 "Created MeetMe conference %d for conference '%s'\n", cnf->zapconf, cnf->confno);
cnf->next = confs; cnf->next = confs;
confs = cnf; confs = cnf;
} else }
ast_log(LOG_WARNING, "Out of memory\n");
} }
cnfout: cnfout:
ast_mutex_unlock(&conflock); ast_mutex_unlock(&conflock);
@@ -851,7 +849,7 @@ static int conf_free(struct ast_conference *conf)
static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags) static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags)
{ {
struct ast_conf_user *user = calloc(1, sizeof(*user)); struct ast_conf_user *user = NULL;
struct ast_conf_user *usr = NULL; struct ast_conf_user *usr = NULL;
int fd; int fd;
struct zt_confinfo ztc, ztc_empty; struct zt_confinfo ztc, ztc_empty;
@@ -887,9 +885,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
ZT_BUFFERINFO bi; ZT_BUFFERINFO bi;
char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET]; char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
char *buf = __buf + AST_FRIENDLY_OFFSET; char *buf = __buf + AST_FRIENDLY_OFFSET;
if (!user) { if (!(user = ast_calloc(1, sizeof(*user)))) {
ast_log(LOG_ERROR, "Out of memory\n");
return ret; return ret;
} }

View File

@@ -41,6 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/channel.h" #include "asterisk/channel.h"
#include "asterisk/pbx.h" #include "asterisk/pbx.h"
#include "asterisk/module.h" #include "asterisk/module.h"
#include "asterisk/utils.h"
static char *tdesc = "Digital Milliwatt (mu-law) Test Application"; static char *tdesc = "Digital Milliwatt (mu-law) Test Application";
@@ -59,11 +60,7 @@ static char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} ;
static void *milliwatt_alloc(struct ast_channel *chan, void *params) static void *milliwatt_alloc(struct ast_channel *chan, void *params)
{ {
int *indexp; return ast_calloc(1, sizeof(int));
indexp = ast_malloc(sizeof(*indexp));
if (indexp == NULL) return(NULL);
*indexp = 0;
return(indexp);
} }
static void milliwatt_release(struct ast_channel *chan, void *data) static void milliwatt_release(struct ast_channel *chan, void *data)

View File

@@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/options.h" #include "asterisk/options.h"
#include "asterisk/app.h" #include "asterisk/app.h"
#include "asterisk/linkedlists.h" #include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
#define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0 #define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
@@ -292,8 +293,7 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
if (!ast_strlen_zero(post_process)) if (!ast_strlen_zero(post_process))
len += strlen(post_process) + 1; len += strlen(post_process) + 1;
if (!(mixmonitor = calloc(1, len))) { if (!(mixmonitor = ast_calloc(1, len))) {
ast_log(LOG_ERROR, "Memory Error!\n");
return; return;
} }

View File

@@ -43,7 +43,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/file.h" #include "asterisk/file.h"
#include "asterisk/app.h" #include "asterisk/app.h"
#include "asterisk/chanvars.h" #include "asterisk/chanvars.h"
#include "asterisk/utils.h"
static const char *tdesc = "Page Multiple Phones"; static const char *tdesc = "Page Multiple Phones";
@@ -100,8 +100,7 @@ static void launch_page(struct ast_channel *chan, const char *meetmeopts, const
struct ast_var_t *varptr; struct ast_var_t *varptr;
pthread_t t; pthread_t t;
pthread_attr_t attr; pthread_attr_t attr;
cd = ast_calloc(1, sizeof(*cd)); if ((cd = ast_calloc(1, sizeof(*cd)))) {
if (cd) {
ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum)); ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname)); ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
ast_copy_string(cd->tech, tech, sizeof(cd->tech)); ast_copy_string(cd->tech, tech, sizeof(cd->tech));

View File

@@ -49,6 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/logger.h" #include "asterisk/logger.h"
#include "asterisk/say.h" #include "asterisk/say.h"
#include "asterisk/lock.h" #include "asterisk/lock.h"
#include "asterisk/utils.h"
static char *tdesc = "Call Parking and Announce Application"; static char *tdesc = "Call Parking and Announce Application";
@@ -94,10 +95,8 @@ static int parkandannounce_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
l=strlen(data)+2; l=strlen(data)+2;
orig_s=malloc(l); if (!(orig_s = ast_malloc(l))) {
if(!orig_s) {
ast_log(LOG_WARNING, "Out of memory\n");
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);
return -1; return -1;
} }