[asterisk-commits] rizzo: trunk r47160 - /trunk/apps/app_dial.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Nov 3 14:51:16 MST 2006
Author: rizzo
Date: Fri Nov 3 15:51:16 2006
New Revision: 47160
URL: http://svn.digium.com/view/asterisk?rev=47160&view=rev
Log:
start integrating the simplifications proposed in bug 0005860,
as usual a bit at a time to ease locating new bugs or fixes
worth merging into other branches.
In this commit, introduce a macro, S_REPLACE, that replaces
a string possibly freeing the previous value.
In one of these places (see the comment marked XXX) the previous
code might leak memory - if so, this ought to be merged in 1.4
The macro might be worth putting in one of the global headers
(e.g. include/asterisk/strings.h) as the construct is used
in a million places in the asterisk code.
Modified:
trunk/apps/app_dial.c
Modified: trunk/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_dial.c?rev=47160&r1=47159&r2=47160&view=diff
==============================================================================
--- trunk/apps/app_dial.c (original)
+++ trunk/apps/app_dial.c Fri Nov 3 15:51:16 2006
@@ -343,6 +343,13 @@
} \
} while (0)
+/* free the buffer if allocated, and set the pointer to the second arg */
+#define S_REPLACE(s, new_val) \
+ do { \
+ if (s) \
+ free(s); \
+ s = (new_val); \
+ } while (0)
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
{
@@ -537,13 +544,9 @@
}
if (in->cid.cid_ani) {
- if (c->cid.cid_ani)
- free(c->cid.cid_ani);
- c->cid.cid_ani = ast_strdup(in->cid.cid_ani);
+ S_REPLACE(c->cid.cid_ani, ast_strdup(in->cid.cid_ani));
}
- if (c->cid.cid_rdnis)
- free(c->cid.cid_rdnis);
- c->cid.cid_rdnis = ast_strdup(S_OR(in->macroexten, in->exten));
+ S_REPLACE(c->cid.cid_rdnis, ast_strdup(S_OR(in->macroexten, in->exten)));
if (ast_call(c, tmpchan, 0)) {
ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
ast_clear_flag(o, DIAL_STILLGOING);
@@ -1148,17 +1151,10 @@
tmp->chan->data = "(Outgoing Line)";
tmp->chan->whentohangup = 0;
- if (tmp->chan->cid.cid_num)
- free(tmp->chan->cid.cid_num);
- tmp->chan->cid.cid_num = ast_strdup(chan->cid.cid_num);
-
- if (tmp->chan->cid.cid_name)
- free(tmp->chan->cid.cid_name);
- tmp->chan->cid.cid_name = ast_strdup(chan->cid.cid_name);
-
- if (tmp->chan->cid.cid_ani)
- free(tmp->chan->cid.cid_ani);
- tmp->chan->cid.cid_ani = ast_strdup(chan->cid.cid_ani);
+ S_REPLACE(tmp->chan->cid.cid_num, ast_strdup(chan->cid.cid_num));
+ S_REPLACE(tmp->chan->cid.cid_name, ast_strdup(chan->cid.cid_name));
+ S_REPLACE(tmp->chan->cid.cid_ani, ast_strdup(chan->cid.cid_ani));
+ S_REPLACE(tmp->chan->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis));
/* Copy language from incoming to outgoing */
ast_string_field_set(tmp->chan, language, chan->language);
@@ -1166,8 +1162,6 @@
tmp->chan->cdrflags = chan->cdrflags;
if (ast_strlen_zero(tmp->chan->musicclass))
ast_string_field_set(tmp->chan, musicclass, chan->musicclass);
- /* XXX don't we free previous values ? */
- tmp->chan->cid.cid_rdnis = ast_strdup(chan->cid.cid_rdnis);
/* Pass callingpres setting */
tmp->chan->cid.cid_pres = chan->cid.cid_pres;
/* Pass type of number */
More information about the asterisk-commits
mailing list