[asterisk-commits] russell: trunk r46885 - /trunk/main/callerid.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Nov 2 07:07:48 MST 2006
Author: russell
Date: Thu Nov 2 08:07:48 2006
New Revision: 46885
URL: http://svn.digium.com/view/asterisk?rev=46885&view=rev
Log:
Change the buffer used in callerid_feed() and callerid_feed_jp() to be
allocated on the stack using alloca() instead of using malloc() since
they are only used locally to these functions.
Modified:
trunk/main/callerid.c
Modified: trunk/main/callerid.c
URL: http://svn.digium.com/view/asterisk/trunk/main/callerid.c?rev=46885&r1=46884&r2=46885&view=diff
==============================================================================
--- trunk/main/callerid.c (original)
+++ trunk/main/callerid.c Thu Nov 2 08:07:48 2006
@@ -286,13 +286,9 @@
int res;
int x;
short *buf;
- short *obuf;
-
- if (!(buf = ast_calloc(1, 2 * len + cid->oldlen))) {
- return -1;
- }
-
- obuf = buf;
+
+ buf = alloca(2 * len + cid->oldlen);
+
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen/2;
@@ -300,7 +296,7 @@
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
while (mylen >= 160) {
- b = b2 = 0 ;
+ b = b2 = 0;
olen = mylen;
res = fsk_serie(&cid->fskd, buf, &mylen, &b);
@@ -527,7 +523,7 @@
cid->oldlen = mylen * 2;
} else
cid->oldlen = 0;
- free(obuf);
+
return 0;
}
@@ -540,24 +536,19 @@
int res;
int x;
short *buf;
- short *obuf;
-
- if (!(buf = ast_calloc(1, 2 * len + cid->oldlen))) {
- return -1;
- }
-
- obuf = buf;
+
+ buf = alloca(2 * len + cid->oldlen);
+
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen/2;
for (x=0;x<len;x++)
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
- while(mylen >= 160) {
+ while (mylen >= 160) {
olen = mylen;
res = fsk_serie(&cid->fskd, buf, &mylen, &b);
if (mylen < 0) {
ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d)\n", mylen);
- free(obuf);
return -1;
}
buf += (olen - mylen);
@@ -591,7 +582,6 @@
case 4: /* Retrieve message */
if (cid->pos >= 128) {
ast_log(LOG_WARNING, "Caller ID too long???\n");
- free(obuf);
return -1;
}
cid->rawdata[cid->pos++] = b;
@@ -677,7 +667,6 @@
strcpy(cid->name, "");
cid->flags |= CID_UNKNOWN_NAME;
}
- free(obuf);
return 1;
break;
default:
@@ -690,7 +679,6 @@
cid->oldlen = mylen * 2;
} else
cid->oldlen = 0;
- free(obuf);
return 0;
}
More information about the asterisk-commits
mailing list