[asterisk-commits] branch russell/ast_malloc - r7628 /team/russell/ast_malloc/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Dec 25 19:35:24 CST 2005


Author: russell
Date: Sun Dec 25 19:35:20 2005
New Revision: 7628

URL: http://svn.digium.com/view/asterisk?rev=7628&view=rev
Log:
cleanups and conversions to the ast_malloc api

Modified:
    team/russell/ast_malloc/acl.c
    team/russell/ast_malloc/app.c
    team/russell/ast_malloc/asterisk.c
    team/russell/ast_malloc/autoservice.c
    team/russell/ast_malloc/callerid.c
    team/russell/ast_malloc/cdr.c
    team/russell/ast_malloc/channel.c
    team/russell/ast_malloc/chanvars.c
    team/russell/ast_malloc/cli.c
    team/russell/ast_malloc/config.c
    team/russell/ast_malloc/db.c
    team/russell/ast_malloc/devicestate.c
    team/russell/ast_malloc/dnsmgr.c
    team/russell/ast_malloc/dsp.c
    team/russell/ast_malloc/enum.c
    team/russell/ast_malloc/file.c
    team/russell/ast_malloc/frame.c
    team/russell/ast_malloc/indications.c

Modified: team/russell/ast_malloc/acl.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/acl.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/acl.c (original)
+++ team/russell/ast_malloc/acl.c Sun Dec 25 19:35:20 2005
@@ -112,9 +112,11 @@
 /* Create duplicate of ha structure */
 static struct ast_ha *ast_duplicate_ha(struct ast_ha *original)
 {
-	struct ast_ha *new_ha = malloc(sizeof(struct ast_ha));
+	struct ast_ha *new_ha = ast_malloc(sizeof(struct ast_ha));
+	
 	/* Copy from original to new object */
-	ast_copy_ha(original, new_ha); 
+	if (new_ha)	
+		ast_copy_ha(original, new_ha); 
 
 	return new_ha;
 }
@@ -143,60 +145,66 @@
 
 struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path)
 {
-	struct ast_ha *ha = malloc(sizeof(struct ast_ha));
+	struct ast_ha *ha;
 	char *nm = "255.255.255.255";
 	char tmp[256];
 	struct ast_ha *prev = NULL;
 	struct ast_ha *ret;
 	int x, z;
 	unsigned int y;
+
 	ret = path;
 	while (path) {
 		prev = path;
 		path = path->next;
 	}
-	if (ha) {
-		ast_copy_string(tmp, stuff, sizeof(tmp));
-		nm = strchr(tmp, '/');
-		if (!nm) {
-			nm = "255.255.255.255";
-		} else {
-			*nm = '\0';
-			nm++;
+
+	ha = ast_calloc(1, sizeof(struct ast_ha));
+	if (!ha)
+		return ret;
+
+	ast_copy_string(tmp, stuff, sizeof(tmp));
+	nm = strchr(tmp, '/');
+	if (!nm) {
+		nm = "255.255.255.255";
+	} else {
+		*nm = '\0';
+		nm++;
+	}
+	if (!strchr(nm, '.')) {
+		if ((sscanf(nm, "%d", &x) == 1) && (x >= 0) && (x <= 32)) {
+			y = 0;
+			for (z=0;z<x;z++) {
+				y >>= 1;
+				y |= 0x80000000;
+			}
+			ha->netmask.s_addr = htonl(y);
 		}
-		if (!strchr(nm, '.')) {
-			if ((sscanf(nm, "%d", &x) == 1) && (x >= 0) && (x <= 32)) {
-				y = 0;
-				for (z=0;z<x;z++) {
-					y >>= 1;
-					y |= 0x80000000;
-				}
-				ha->netmask.s_addr = htonl(y);
-			}
-		} else if (!inet_aton(nm, &ha->netmask)) {
-			ast_log(LOG_WARNING, "%s is not a valid netmask\n", nm);
-			free(ha);
-			return path;
-		}
-		if (!inet_aton(tmp, &ha->netaddr)) {
-			ast_log(LOG_WARNING, "%s is not a valid IP\n", tmp);
-			free(ha);
-			return path;
-		}
-		ha->netaddr.s_addr &= ha->netmask.s_addr;
-		if (!strncasecmp(sense, "p", 1)) {
-			ha->sense = AST_SENSE_ALLOW;
-		} else {
-			ha->sense = AST_SENSE_DENY;
-		}
-		ha->next = NULL;
-		if (prev) {
-			prev->next = ha;
-		} else {
-			ret = ha;
-		}
-	}
+	} else if (!inet_aton(nm, &ha->netmask)) {
+		ast_log(LOG_WARNING, "%s is not a valid netmask\n", nm);
+		free(ha);
+		return path;
+	}
+	if (!inet_aton(tmp, &ha->netaddr)) {
+		ast_log(LOG_WARNING, "%s is not a valid IP\n", tmp);
+		free(ha);
+		return path;
+	}
+	ha->netaddr.s_addr &= ha->netmask.s_addr;
+	if (!strncasecmp(sense, "p", 1)) {
+		ha->sense = AST_SENSE_ALLOW;
+	} else {
+		ha->sense = AST_SENSE_DENY;
+	}
+	ha->next = NULL;
+	if (prev) {
+		prev->next = ha;
+	} else {
+		ret = ha;
+	}
+	
 	ast_log(LOG_DEBUG, "%s/%s appended to acl for peer\n", stuff, nm);
+	
 	return ret;
 }
 

Modified: team/russell/ast_malloc/app.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/app.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/app.c (original)
+++ team/russell/ast_malloc/app.c Sun Dec 25 19:35:20 2005
@@ -398,8 +398,8 @@
 {
 	struct linear_state *lin;
 	char tmpf[256];
-	int res = -1;
 	int autoclose = 0;
+	
 	if (fd < 0) {
 		if (ast_strlen_zero(filename))
 			return -1;
@@ -414,15 +414,16 @@
 			return -1;
 		}
 	}
-	lin = malloc(sizeof(struct linear_state));
-	if (lin) {
-		memset(lin, 0, sizeof(lin));
-		lin->fd = fd;
-		lin->allowoverride = allowoverride;
-		lin->autoclose = autoclose;
-		res = ast_activate_generator(chan, &linearstream, lin);
-	}
-	return res;
+
+	lin = ast_calloc(1, sizeof(struct linear_state));
+	if (!lin)
+		return -1;
+
+	lin->fd = fd;
+	lin->allowoverride = allowoverride;
+	lin->autoclose = autoclose;
+	
+	return ast_activate_generator(chan, &linearstream, lin);
 }
 
 int ast_control_streamfile(struct ast_channel *chan, const char *file,
@@ -1486,7 +1487,8 @@
 	struct stat filesize;
 	int count=0;
 	int res;
-	if(stat(filename,&filesize)== -1){
+
+	if (stat(filename,&filesize) == -1){
 		ast_log(LOG_WARNING,"Error can't stat %s\n", filename);
 		return NULL;
 	}
@@ -1496,19 +1498,24 @@
 		ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
 		return NULL;
 	}
-	output=(char *)malloc(count);
-	if (output) {
-		res = read(fd, output, count - 1);
-		if (res == count - 1) {
-			output[res] = '\0';
-		} else {
-			ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count -  1, strerror(errno));
-			free(output);
-			output = NULL;
-		}
-	} else 
-		ast_log(LOG_WARNING, "Out of memory!\n");
+
+	output = ast_calloc(1, count);
+	if (!output) {
+		close(fd);
+		return NULL;
+	}
+		
+	res = read(fd, output, count - 1);
+	if (res == count - 1) {
+		output[res] = '\0';
+	} else {
+		ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count -  1, strerror(errno));
+		free(output);
+		output = NULL;
+	}
+	
 	close(fd);
+	
 	return output;
 }
 

Modified: team/russell/ast_malloc/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/asterisk.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/asterisk.c (original)
+++ team/russell/ast_malloc/asterisk.c Sun Dec 25 19:35:20 2005
@@ -225,7 +225,7 @@
 	work = ast_strip(ast_strip_quoted(work, "$", "$"));
 	version_length = strlen(work) + 1;
 
-	new = calloc(1, sizeof(*new) + version_length);
+	new = ast_calloc(1, sizeof(*new) + version_length);
 	if (!new)
 		return;
 
@@ -341,20 +341,21 @@
 
 int ast_register_atexit(void (*func)(void))
 {
-	int res = -1;
 	struct ast_atexit *ae;
+	
 	ast_unregister_atexit(func);
-	ae = malloc(sizeof(struct ast_atexit));
+	
+	ae = ast_calloc(1, sizeof(struct ast_atexit));
+	if (!ae)
+		return -1;
+	
 	ast_mutex_lock(&atexitslock);
-	if (ae) {
-		memset(ae, 0, sizeof(struct ast_atexit));
-		ae->next = atexits;
-		ae->func = func;
-		atexits = ae;
-		res = 0;
-	}
+	ae->next = atexits;
+	ae->func = func;
+	atexits = ae;
 	ast_mutex_unlock(&atexitslock);
-	return res;
+	
+	return 0;
 }
 
 void ast_unregister_atexit(void (*func)(void))
@@ -1382,7 +1383,7 @@
 			break;
 		if (matches + 1 >= match_list_len) {
 			match_list_len <<= 1;
-			match_list = realloc(match_list, match_list_len * sizeof(char *));
+			match_list = ast_realloc(match_list, match_list_len * sizeof(char *));
 		}
 
 		match_list[matches++] = strdup(retstr);
@@ -1392,7 +1393,7 @@
 		return (char **) NULL;
 
 	if (matches>= match_list_len)
-		match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
+		match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *));
 
 	match_list[matches] = (char *) NULL;
 
@@ -1494,7 +1495,7 @@
 			char *mbuf;
 			int mlen = 0, maxmbuf = 2048;
 			/* Start with a 2048 byte buffer */
-			mbuf = malloc(maxmbuf);
+			mbuf = ast_malloc(maxmbuf);
 			if (!mbuf)
 				return (char *)(CC_ERROR);
 			snprintf(buf, sizeof(buf),"_COMMAND MATCHESARRAY \"%s\" \"%s\"", lf->buffer, ptr); 
@@ -1505,7 +1506,7 @@
 				if (mlen + 1024 > maxmbuf) {
 					/* Every step increment buffer 1024 bytes */
 					maxmbuf += 1024;
-					mbuf = realloc(mbuf, maxmbuf);
+					mbuf = ast_realloc(mbuf, maxmbuf);
 					if (!mbuf)
 						return (char *)(CC_ERROR);
 				}

Modified: team/russell/ast_malloc/autoservice.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/autoservice.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/autoservice.c (original)
+++ team/russell/ast_malloc/autoservice.c Sun Dec 25 19:35:20 2005
@@ -105,34 +105,39 @@
 	int res = -1;
 	struct asent *as;
 	int needstart;
+
 	ast_mutex_lock(&autolock);
+	
 	needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
-	as = aslist;
-	while(as) {
-		if (as->chan == chan)
-			break;
-		as = as->next;
-	}
-	if (!as) {
-		as = malloc(sizeof(struct asent));
-		if (as) {
-			memset(as, 0, sizeof(struct asent));
-			as->chan = chan;
-			as->next = aslist;
-			aslist = as;
-			res = 0;
-			if (needstart) {
-				if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
-					ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
-					free(aslist);
-					aslist = NULL;
-					res = -1;
-				} else
-					pthread_kill(asthread, SIGURG);
-			}
+	
+	for (as = aslist; as; as = as->next) {	
+		if (as->chan == chan) {
+			ast_mutex_unlock(&autolock);
+			return res;	
 		}
 	}
+
+	as = ast_calloc(1, sizeof(struct asent));
+	if (!as) {
+		ast_mutex_unlock(&autolock);
+		return res;
+	}	
+	as->chan = chan;
+	as->next = aslist;
+	aslist = as;
+	res = 0;
+	if (needstart) {
+		if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
+			ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
+			free(aslist);
+			aslist = NULL;
+			res = -1;
+		} else
+			pthread_kill(asthread, SIGURG);
+	}
+
 	ast_mutex_unlock(&autolock);
+	
 	return res;
 }
 

Modified: team/russell/ast_malloc/callerid.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/callerid.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/callerid.c (original)
+++ team/russell/ast_malloc/callerid.c Sun Dec 25 19:35:20 2005
@@ -127,32 +127,31 @@
 struct callerid_state *callerid_new(int cid_signalling)
 {
 	struct callerid_state *cid;
-	cid = malloc(sizeof(struct callerid_state));
-	if (cid) {
-		memset(cid, 0, sizeof(struct callerid_state));
-		cid->fskd.spb = 7;		/* 1200 baud */
-		cid->fskd.hdlc = 0;		/* Async */
-		cid->fskd.nbit = 8;		/* 8 bits */
-		cid->fskd.nstop = 1;	/* 1 stop bit */
-		cid->fskd.paridad = 0;	/* No parity */
-		cid->fskd.bw=1;			/* Filter 800 Hz */
-		if (cid_signalling == 2) { /* v23 signalling */
-			cid->fskd.f_mark_idx =  4;	/* 1300 Hz */
-			cid->fskd.f_space_idx = 5;	/* 2100 Hz */
-		} else { /* Bell 202 signalling as default */ 
-			cid->fskd.f_mark_idx =  2;	/* 1200 Hz */
-			cid->fskd.f_space_idx = 3;	/* 2200 Hz */
-		}
-		cid->fskd.pcola = 0;		/* No clue */
-		cid->fskd.cont = 0;			/* Digital PLL reset */
-		cid->fskd.x0 = 0.0;
-		cid->fskd.state = 0;
-		memset(cid->name, 0, sizeof(cid->name));
-		memset(cid->number, 0, sizeof(cid->number));
-		cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
-		cid->pos = 0;
-	} else
-		ast_log(LOG_WARNING, "Out of memory\n");
+
+	cid = ast_calloc(1, sizeof(struct callerid_state));
+	if (!cid)
+		return NULL;
+		
+	cid->fskd.spb = 7;		/* 1200 baud */
+	cid->fskd.hdlc = 0;		/* Async */
+	cid->fskd.nbit = 8;		/* 8 bits */
+	cid->fskd.nstop = 1;	/* 1 stop bit */
+	cid->fskd.paridad = 0;	/* No parity */
+	cid->fskd.bw=1;			/* Filter 800 Hz */
+	if (cid_signalling == 2) { /* v23 signalling */
+		cid->fskd.f_mark_idx =  4;	/* 1300 Hz */
+		cid->fskd.f_space_idx = 5;	/* 2100 Hz */
+	} else { /* Bell 202 signalling as default */ 
+		cid->fskd.f_mark_idx =  2;	/* 1200 Hz */
+		cid->fskd.f_space_idx = 3;	/* 2200 Hz */
+	}
+	cid->fskd.pcola = 0;		/* No clue */
+	cid->fskd.cont = 0;			/* Digital PLL reset */
+	cid->fskd.x0 = 0.0;
+	cid->fskd.state = 0;
+	cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
+	cid->pos = 0;
+	
 	return cid;
 }
 
@@ -258,13 +257,14 @@
 	int b = 'X';
 	int res;
 	int x;
-	short *buf = malloc(2 * len + cid->oldlen);
-	short *obuf = buf;
-	if (!buf) {
-		ast_log(LOG_WARNING, "Out of memory\n");
+	short *buf;
+	short *obuf;
+
+	buf = ast_malloc(2 * len + cid->oldlen);	
+	if (!buf)
 		return -1;
-	}
-	memset(buf, 0, 2 * len + cid->oldlen);
+	obuf = buf;
+
 	memcpy(buf, cid->oldstuff, cid->oldlen);
 	mylen += cid->oldlen/2;
 	for (x=0;x<len;x++) 

Modified: team/russell/ast_malloc/cdr.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/cdr.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/cdr.c (original)
+++ team/russell/ast_malloc/cdr.c Sun Dec 25 19:35:20 2005
@@ -126,11 +126,10 @@
 		return -1;
 	}
 
-	i = malloc(sizeof(*i));
+	i = ast_calloc(1, sizeof(*i));
 	if (!i) 	
 		return -1;
 
-	memset(i, 0, sizeof(*i));
 	i->be = be;
 	ast_copy_string(i->name, name, sizeof(i->name));
 	ast_copy_string(i->desc, desc, sizeof(i->desc));
@@ -437,9 +436,7 @@
 {
 	struct ast_cdr *cdr;
 
-	cdr = malloc(sizeof(*cdr));
-	if (cdr)
-		memset(cdr, 0, sizeof(*cdr));
+	cdr = ast_calloc(1, sizeof(*cdr));
 
 	return cdr;
 }
@@ -873,7 +870,7 @@
 static int init_batch(void)
 {
 	/* This is the single meta-batch used to keep track of all CDRs during the entire life of the program */
-	batch = malloc(sizeof(*batch));
+	batch = ast_calloc(1, sizeof(*batch));
 	if (!batch) {
 		ast_log(LOG_WARNING, "CDR: out of memory while trying to handle batched records, data will most likely be lost\n");
 		return -1;
@@ -984,14 +981,13 @@
 		ast_log(LOG_DEBUG, "CDR detaching from this thread\n");
 
 	/* we'll need a new tail for every CDR */
-	newtail = malloc(sizeof(*newtail));
+	newtail = ast_calloc(1, sizeof(*newtail));
 	if (!newtail) {
 		ast_log(LOG_WARNING, "CDR: out of memory while trying to detach, will try in this thread instead\n");
 		post_cdr(cdr);
 		ast_cdr_free(cdr);
 		return;
 	}
-	memset(newtail, 0, sizeof(*newtail));
 
 	/* don't traverse a whole list (just keep track of the tail) */
 	ast_mutex_lock(&cdr_batch_lock);

Modified: team/russell/ast_malloc/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/channel.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/channel.c (original)
+++ team/russell/ast_malloc/channel.c Sun Dec 25 19:35:20 2005
@@ -319,8 +319,7 @@
 
 	ast_mutex_lock(&chlock);
 
-	chan = backends;
-	while (chan) {
+	for (chan = backends; chan; chan = chan->next) {
 		if (!strcasecmp(tech->type, chan->tech->type)) {
 			ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
 			ast_mutex_unlock(&chlock);
@@ -329,9 +328,8 @@
 		chan = chan->next;
 	}
 
-	chan = malloc(sizeof(*chan));
+	chan = ast_calloc(1, sizeof(*chan));
 	if (!chan) {
-		ast_log(LOG_WARNING, "Out of memory\n");
 		ast_mutex_unlock(&chlock);
 		return -1;
 	}
@@ -526,13 +524,10 @@
 		return NULL;
 	}
 
-	tmp = malloc(sizeof(struct ast_channel));
-	if (!tmp) {
-		ast_log(LOG_WARNING, "Channel allocation failed: Out of memory\n");
+	tmp = ast_calloc(1, sizeof(struct ast_channel));
+	if (!tmp)
 		return NULL;
-	}
-
-	memset(tmp, 0, sizeof(struct ast_channel));
+
 	tmp->sched = sched_context_create();
 	if (!tmp->sched) {
 		ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
@@ -988,10 +983,8 @@
 	}
 
 	if (!chan->spies) {
-		if (!(chan->spies = calloc(1, sizeof(*chan->spies)))) {
-			ast_log(LOG_WARNING, "Memory allocation failure\n");
+		if (!(chan->spies = ast_calloc(1, sizeof(*chan->spies))))
 			return -1;
-		}
 
 		AST_LIST_HEAD_INIT_NOLOCK(&chan->spies->list);
 		AST_LIST_INSERT_HEAD(&chan->spies->list, spy, list);
@@ -3583,10 +3576,10 @@
 	struct tonepair_state *ts;
 	struct tonepair_def *td = params;
 
-	ts = malloc(sizeof(struct tonepair_state));
+	ts = ast_calloc(1, sizeof(struct tonepair_state));
 	if (!ts)
 		return NULL;
-	memset(ts, 0, sizeof(struct tonepair_state));
+
 	ts->origwfmt = chan->writeformat;
 	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
@@ -3999,7 +3992,7 @@
 {
 	struct ast_silence_generator *state;
 
-	if (!(state = calloc(1, sizeof(*state)))) {
+	if (!(state = ast_calloc(1, sizeof(*state)))) {
 		ast_log(LOG_WARNING, "Could not allocate state structure\n");
 		return NULL;
 	}

Modified: team/russell/ast_malloc/chanvars.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/chanvars.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/chanvars.c (original)
+++ team/russell/ast_malloc/chanvars.c Sun Dec 25 19:35:20 2005
@@ -38,12 +38,9 @@
 	int i;
 	struct ast_var_t *var;
 	
-	var = calloc(sizeof(struct ast_var_t) + strlen(name) + 1 + strlen(value) + 1, sizeof(char));
-
-	if (var == NULL) {
-		ast_log(LOG_WARNING, "Out of memory\n");
+	var = ast_calloc(sizeof(struct ast_var_t) + strlen(name) + 1 + strlen(value) + 1, sizeof(char));
+	if (!var)
 		return NULL;
-	}
 
 	i = strlen(name) + 1;
 	ast_copy_string(var->name, name, i);

Modified: team/russell/ast_malloc/cli.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/cli.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/cli.c (original)
+++ team/russell/ast_malloc/cli.c Sun Dec 25 19:35:20 2005
@@ -567,10 +567,12 @@
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
-	buf = malloc(buflen);
+
+	buf = ast_malloc(buflen);
 	if (!buf)
 		return RESULT_FAILURE;
 	buf[len] = '\0';
+	
 	matches = ast_cli_completion_matches(argv[2], argv[3]);
 	if (matches) {
 		for (x=0; matches[x]; x++) {
@@ -581,7 +583,7 @@
 			if (len + matchlen >= buflen) {
 				buflen += matchlen * 3;
 				obuf = buf;
-				buf = realloc(obuf, buflen);
+				buf = ast_realloc(obuf, buflen);
 				if (!buf) 
 					/* Out of memory...  Just free old buffer and be done */
 					free(obuf);
@@ -1330,13 +1332,16 @@
 		max_equal = i;
 	}
 
-	retstr = malloc(max_equal + 1);
+	retstr = ast_malloc(max_equal + 1);
+	if (!netstr)
+		return NULL;		
+
 	strncpy(retstr, match_list[1], max_equal);
 	retstr[max_equal] = '\0';
 	match_list[0] = retstr;
 
 	if (matches + 1 >= match_list_len)
-		match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
+		match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(char *));
 	match_list[matches + 1] = (char *) NULL;
 
 	return match_list;

Modified: team/russell/ast_malloc/config.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/config.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/config.c (original)
+++ team/russell/ast_malloc/config.c Sun Dec 25 19:35:20 2005
@@ -101,14 +101,15 @@
 	struct ast_variable *variable;
 
 	int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable);
-	variable = malloc(length);
-	if (variable) {
-		memset(variable, 0, length);
-		variable->name = variable->stuff;
-		variable->value = variable->stuff + strlen(name) + 1;		
-		strcpy(variable->name,name);
-		strcpy(variable->value,value);
-	}
+	
+	variable = ast_calloc(1, length);
+	if (!variable)
+		return NULL;
+
+	variable->name = variable->stuff;
+	variable->value = variable->stuff + strlen(name) + 1;		
+	strcpy(variable->name,name);
+	strcpy(variable->value,value);
 
 	return variable;
 }
@@ -201,11 +202,11 @@
 {
 	struct ast_category *category;
 
-	category = malloc(sizeof(struct ast_category));
-	if (category) {
-		memset(category, 0, sizeof(struct ast_category));
-		ast_copy_string(category->name, name, sizeof(category->name));
-	}
+	category = ast_calloc(1, sizeof(struct ast_category));
+	if (!category)
+		return NULL;
+
+	ast_copy_string(category->name, name, sizeof(category->name));
 
 	return category;
 }
@@ -327,11 +328,9 @@
 {
 	struct ast_config *config;
 
-	config = malloc(sizeof(*config));
-	if (config) {
-		memset(config, 0, sizeof(*config));
+	config = ast_calloc(1, sizeof(*config));
+	if (config)
 		config->max_include_level = MAX_INCLUDE_LEVEL;
-	}
 
 	return config;
 }
@@ -766,12 +765,11 @@
 	length += strlen(database) + 1;
 	if (table)
 		length += strlen(table) + 1;
-	map = malloc(length);
-
+	
+	map = ast_calloc(1, length);
 	if (!map)
 		return -1;
 
-	memset(map, 0, length);
 	map->name = map->stuff;
 	strcpy(map->name, name);
 	map->driver = map->name + strlen(map->name) + 1;

Modified: team/russell/ast_malloc/db.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/db.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/db.c (original)
+++ team/russell/ast_malloc/db.c Sun Dec 25 19:35:20 2005
@@ -438,7 +438,7 @@
 			values = "<bad value>";
 		}
 		if (keymatch(keys, prefix)) {
-			cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
+			cur = ast_malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
 			if (cur) {
 				cur->next = NULL;
 				cur->key = cur->data + strlen(values) + 1;

Modified: team/russell/ast_malloc/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/devicestate.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/devicestate.c (original)
+++ team/russell/ast_malloc/devicestate.c Sun Dec 25 19:35:20 2005
@@ -145,7 +145,7 @@
 	if (!callback)
 		return -1;
 
-	devcb = calloc(1, sizeof(*devcb));
+	devcb = ast_calloc(1, sizeof(*devcb));
 	if (!devcb)
 		return -1;
 
@@ -204,7 +204,7 @@
 	if (tmp)
 		*tmp = '\0';
 	if (change_thread != AST_PTHREADT_NULL)
-		change = calloc(1, sizeof(*change) + strlen(device));
+		change = ast_calloc(1, sizeof(*change) + strlen(device));
 
 	if (!change) {
 		/* we could not allocate a change struct, or */

Modified: team/russell/ast_malloc/dnsmgr.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/dnsmgr.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/dnsmgr.c (original)
+++ team/russell/ast_malloc/dnsmgr.c Sun Dec 25 19:35:20 2005
@@ -85,7 +85,7 @@
 	if (!result || ast_strlen_zero(name))
 		return NULL;
 
-	entry = calloc(1, sizeof(*entry) + strlen(name));
+	entry = ast_calloc(1, sizeof(*entry) + strlen(name));
 	if (!entry)
 		return NULL;
 

Modified: team/russell/ast_malloc/dsp.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/dsp.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/dsp.c (original)
+++ team/russell/ast_malloc/dsp.c Sun Dec 25 19:35:20 2005
@@ -1574,17 +1574,18 @@
 {
 	struct ast_dsp *dsp;
 
-	dsp = malloc(sizeof(struct ast_dsp));
-	if (dsp) {
-		memset(dsp, 0, sizeof(struct ast_dsp));
-		dsp->threshold = DEFAULT_THRESHOLD;
-		dsp->features = DSP_FEATURE_SILENCE_SUPPRESS;
-		dsp->busycount = DSP_HISTORY;
-		/* Initialize DTMF detector */
-		ast_dtmf_detect_init(&dsp->td.dtmf);
-		/* Initialize initial DSP progress detect parameters */
-		ast_dsp_prog_reset(dsp);
-	}
+	dsp = ast_calloc(1, sizeof(struct ast_dsp));
+	if (!dsp)
+		return NULL;
+		
+	dsp->threshold = DEFAULT_THRESHOLD;
+	dsp->features = DSP_FEATURE_SILENCE_SUPPRESS;
+	dsp->busycount = DSP_HISTORY;
+	/* Initialize DTMF detector */
+	ast_dtmf_detect_init(&dsp->td.dtmf);
+	/* Initialize initial DSP progress detect parameters */
+	ast_dsp_prog_reset(dsp);
+	
 	return dsp;
 }
 

Modified: team/russell/ast_malloc/enum.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/enum.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/enum.c (original)
+++ team/russell/ast_malloc/enum.c Sun Dec 25 19:35:20 2005
@@ -358,7 +358,7 @@
                        c->position++;
                        snprintf(c->dst, c->dstlen, "%d", c->position);
                } else  {
-                       p = realloc(c->naptr_rrs, sizeof(struct enum_naptr_rr)*(c->naptr_rrs_count+1));
+                       p = ast_realloc(c->naptr_rrs, sizeof(struct enum_naptr_rr)*(c->naptr_rrs_count+1));
                        if (p) {
                                c->naptr_rrs = (struct enum_naptr_rr*)p;
                                memcpy(&c->naptr_rrs[c->naptr_rrs_count].naptr, answer, sizeof(struct naptr));
@@ -610,11 +610,12 @@
 {
 	struct enum_search *tmp;
 
-	tmp = malloc(sizeof(struct enum_search));
-	if (tmp) {
-		memset(tmp, 0, sizeof(struct enum_search));
-		ast_copy_string(tmp->toplev, s, sizeof(tmp->toplev));
-	}
+	tmp = ast_calloc(1, sizeof(struct enum_search));
+	if (!tmp)
+		return NULL;
+	
+	ast_copy_string(tmp->toplev, s, sizeof(tmp->toplev));
+	
 	return tmp;
 }
 

Modified: team/russell/ast_malloc/file.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/file.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/file.c (original)
+++ team/russell/ast_malloc/file.c Sun Dec 25 19:35:20 2005
@@ -127,9 +127,8 @@
 		}
 		tmp = tmp->next;
 	}
-	tmp = malloc(sizeof(struct ast_format));
+	tmp = ast_calloc(1, sizeof(struct ast_format));
 	if (!tmp) {
-		ast_log(LOG_WARNING, "Out of memory\n");
 		ast_mutex_unlock(&formatlock);
 		return -1;
 	}
@@ -150,6 +149,7 @@
 	ast_mutex_unlock(&formatlock);
 	if (option_verbose > 1)
 		ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", name, exts);
+
 	return 0;
 }
 
@@ -306,7 +306,7 @@
 
 	if (filename[0] == '/') {
 		fnsize = strlen(filename) + strlen(type) + 2;
-		fn = malloc(fnsize);
+		fn = ast_malloc(fnsize);
 		if (fn)
 			snprintf(fn, fnsize, "%s.%s", filename, type);
 	} else {
@@ -314,7 +314,7 @@
 
 		snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_VAR_DIR, "sounds");
 		fnsize = strlen(tmp) + strlen(filename) + strlen(type) + 3;
-		fn = malloc(fnsize);
+		fn = ast_malloc(fnsize);
 		if (fn)
 			snprintf(fn, fnsize, "%s/%s.%s", tmp, filename, type);
 	}

Modified: team/russell/ast_malloc/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/frame.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/frame.c (original)
+++ team/russell/ast_malloc/frame.c Sun Dec 25 19:35:20 2005
@@ -118,7 +118,7 @@
 	struct ast_smoother *s;
 	if (size < 1)
 		return NULL;
-	s = malloc(sizeof(struct ast_smoother));
+	s = ast_malloc(sizeof(struct ast_smoother));
 	if (s)
 		ast_smoother_reset(s, size);
 	return s;
@@ -248,9 +248,8 @@
 static struct ast_frame *ast_frame_header_new(void)
 {
 	struct ast_frame *f;
-	f = malloc(sizeof(struct ast_frame));
-	if (f)
-		memset(f, 0, sizeof(struct ast_frame));
+
+	f = ast_calloc(1, sizeof(struct ast_frame));
 #ifdef TRACE_FRAMES
 	if (f) {
 		headers++;
@@ -358,7 +357,7 @@
 		srclen = strlen(f->src);
 	if (srclen > 0)
 		len += srclen + 1;
-	buf = malloc(len);
+	buf = ast_malloc(len);
 	if (!buf)
 		return NULL;
 	out = buf;

Modified: team/russell/ast_malloc/indications.c
URL: http://svn.digium.com/view/asterisk/team/russell/ast_malloc/indications.c?rev=7628&r1=7627&r2=7628&view=diff
==============================================================================
--- team/russell/ast_malloc/indications.c (original)
+++ team/russell/ast_malloc/indications.c Sun Dec 25 19:35:20 2005
@@ -113,10 +113,12 @@
 static void * playtones_alloc(struct ast_channel *chan, void *params)
 {
 	struct playtones_def *pd = params;
-	struct playtones_state *ps = malloc(sizeof(struct playtones_state));
+	struct playtones_state *ps;
+
+	ps = ast_calloc(1, sizeof(struct playtones_state));
 	if (!ps)
 		return NULL;
-	memset(ps, 0, sizeof(struct playtones_state));
+
 	ps->origwfmt = chan->writeformat;
 	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
 		ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
@@ -300,7 +302,7 @@
 				freq2 = 0;
 		}
 
-		d.items = realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
+		d.items = ast_realloc(d.items,(d.nitems+1)*sizeof(struct playtones_item));
 		if (d.items == NULL) {
 			ast_log(LOG_WARNING, "Realloc failed!\n");
 			return -1;
@@ -547,9 +549,8 @@
 	}
 	if (!ts) {
 		/* not there, we have to add */
-		ts = malloc(sizeof(struct tone_zone_sound));
+		ts = ast_calloc(1, sizeof(struct tone_zone_sound));
 		if (!ts) {
-			ast_log(LOG_WARNING, "Out of memory\n");
 			ast_mutex_unlock(&tzlock);
 			return -2;
 		}



More information about the asterisk-commits mailing list