Hello,<br> This should be merged in 1.6.0 and 1.6.1 or just blocked in that branches?<br><br>Thanks in advanced.<br><br><div class="gmail_quote">On Wed, Dec 3, 2008 at 5:25 PM, SVN commits to the Asterisk project <span dir="ltr"><<a href="mailto:asterisk-commits@lists.digium.com">asterisk-commits@lists.digium.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Author: eliel<br>
Date: Wed Dec 3 13:25:30 2008<br>
New Revision: 160663<br>
<br>
URL: <a href="http://svn.digium.com/view/asterisk?view=rev&rev=160663" target="_blank">http://svn.digium.com/view/asterisk?view=rev&rev=160663</a><br>
Log:<br>
- iax2-provision was not freeing iax_templates structure when unloading the chan_iax2.so module.<br>
- Move the code to start using the LIST macros.<br>
<br>
Review: <a href="http://reviewboard.digium.com/r/72" target="_blank">http://reviewboard.digium.com/r/72</a><br>
<br>
(closes issue #13232)<br>
Reported by: eliel<br>
Patches:<br>
iax2-provision.patch.txt uploaded by eliel (license 64)<br>
(with minor changes pointed by Mark Michelson on review board)<br>
Tested by: eliel<br>
<br>
<br>
Modified:<br>
trunk/channels/iax2-provision.c<br>
<br>
Modified: trunk/channels/iax2-provision.c<br>
URL: <a href="http://svn.digium.com/view/asterisk/trunk/channels/iax2-provision.c?view=diff&rev=160663&r1=160662&r2=160663" target="_blank">http://svn.digium.com/view/asterisk/trunk/channels/iax2-provision.c?view=diff&rev=160663&r1=160662&r2=160663</a><br>
==============================================================================<br>
--- trunk/channels/iax2-provision.c (original)<br>
+++ trunk/channels/iax2-provision.c Wed Dec 3 13:25:30 2008<br>
@@ -51,7 +51,6 @@<br>
int dead;<br>
char name[80];<br>
char src[80];<br>
- struct iax_template *next;<br>
char user[20];<br>
char pass[20];<br>
char lang[10];<br>
@@ -61,8 +60,13 @@<br>
unsigned int altserver;<br>
unsigned int flags;<br>
unsigned int format;<br>
- unsigned int tos;<br>
-} *templates;<br>
+ unsigned int tos;<br>
+ AST_LIST_ENTRY(iax_template) list;<br>
+};<br>
+<br>
+static AST_LIST_HEAD_NOLOCK_STATIC(templates, iax_template);<br>
+<br>
+AST_MUTEX_DEFINE_STATIC(provlock);<br>
<br>
static struct iax_flag {<br>
char *name;<br>
@@ -132,20 +136,40 @@<br>
}<br>
return flags;<br>
}<br>
-AST_MUTEX_DEFINE_STATIC(provlock);<br>
+<br>
+static void iax_template_copy(struct iax_template *dst, struct iax_template *src)<br>
+{<br>
+ if (!dst || !src) {<br>
+ return;<br>
+ }<br>
+<br>
+ dst->dead = src->dead;<br>
+ ast_copy_string(dst->name, src->name, sizeof(dst->name));<br>
+ ast_copy_string(dst->src, src->src, sizeof(dst->src));<br>
+ ast_copy_string(dst->user, src->user, sizeof(dst->user));<br>
+ ast_copy_string(dst->pass, src->pass, sizeof(dst->pass));<br>
+ ast_copy_string(dst->lang, src->lang, sizeof(dst->lang));<br>
+ dst->port = src->port;<br>
+ dst->server = src->server;<br>
+ dst->altserver = src->altserver;<br>
+ dst->flags = src->flags;<br>
+ dst->format = src->format;<br>
+ dst->tos = src->tos;<br>
+}<br>
<br>
static struct iax_template *iax_template_find(const char *s, int allowdead)<br>
{<br>
struct iax_template *cur;<br>
- cur = templates;<br>
- while(cur) {<br>
+<br>
+ AST_LIST_TRAVERSE(&templates, cur, list) {<br>
if (!strcasecmp(s, cur->name)) {<br>
- if (!allowdead && cur->dead)<br>
+ if (!allowdead && cur->dead) {<br>
cur = NULL;<br>
+ }<br>
break;<br>
}<br>
- cur = cur->next;<br>
- }<br>
+ }<br>
+<br>
return cur;<br>
}<br>
<br>
@@ -158,7 +182,7 @@<br>
<br>
if (pos == 3) {<br>
ast_mutex_lock(&provlock);<br>
- for (c = templates; c; c = c->next) {<br>
+ AST_LIST_TRAVERSE(&templates, c, list) {<br>
if (!strncasecmp(word, c->name, wordlen) && ++which > state) {<br>
ret = ast_strdup(c->name);<br>
break;<br>
@@ -278,16 +302,15 @@<br>
}<br>
if (!src)<br>
return -1;<br>
- ast_mutex_lock(&provlock);<br>
+ ast_mutex_lock(&provlock);<br>
/* Backup old data */<br>
- memcpy(&tmp, cur, sizeof(tmp));<br>
+ iax_template_copy(&tmp, cur);<br>
/* Restore from src */<br>
- memcpy(cur, src, sizeof(tmp));<br>
+ iax_template_copy(cur, src);<br>
/* Restore important headers */<br>
memcpy(cur->name, <a href="http://tmp.name" target="_blank">tmp.name</a>, sizeof(cur->name));<br>
cur->dead = tmp.dead;<br>
- cur->next = tmp.next;<br>
- ast_mutex_unlock(&provlock);<br>
+ ast_mutex_unlock(&provlock);<br>
}<br>
if (def)<br>
strncpy(cur->src, def, sizeof(cur->src) - 1);<br>
@@ -359,12 +382,8 @@<br>
/* Find an already existing one if there */<br>
struct iax_template *cur;<br>
int mallocd = 0;<br>
- cur = templates;<br>
- while(cur) {<br>
- if (!strcasecmp(cur->name, s))<br>
- break;<br>
- cur = cur->next;<br>
- }<br>
+<br>
+ cur = iax_template_find(s, 1 /* allow dead */);<br>
if (!cur) {<br>
mallocd = 1;<br>
cur = ast_calloc(1, sizeof(*cur));<br>
@@ -382,8 +401,7 @@<br>
/* Link if we're mallocd */<br>
if (mallocd) {<br>
ast_mutex_lock(&provlock);<br>
- cur->next = templates;<br>
- templates = cur;<br>
+ AST_LIST_INSERT_HEAD(&templates, cur, list);<br>
ast_mutex_unlock(&provlock);<br>
}<br>
return 0;<br>
@@ -432,8 +450,9 @@<br>
<br>
if ((a->argc != 3) && (a->argc != 4))<br>
return CLI_SHOWUSAGE;<br>
+<br>
ast_mutex_lock(&provlock);<br>
- for (cur = templates;cur;cur = cur->next) {<br>
+ AST_LIST_TRAVERSE(&templates, cur, list) {<br>
if ((a->argc == 3) || (!strcasecmp(a->argv[3], cur->name))) {<br>
if (found)<br>
ast_cli(a->fd, "\n");<br>
@@ -475,17 +494,35 @@<br>
return 0;<br>
}<br>
<br>
+static void iax_provision_free_templates(int dead)<br>
+{<br>
+ struct iax_template *cur;<br>
+<br>
+ /* Drop dead or not (depending on dead) entries while locked */<br>
+ ast_mutex_lock(&provlock);<br>
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&templates, cur, list) {<br>
+ if ((dead && cur->dead) || !dead) {<br>
+ AST_LIST_REMOVE_CURRENT(list);<br>
+ ast_free(cur);<br>
+ }<br>
+ }<br>
+ AST_LIST_TRAVERSE_SAFE_END;<br>
+ ast_mutex_unlock(&provlock);<br>
+}<br>
+<br>
int iax_provision_unload(void)<br>
{<br>
provinit = 0;<br>
ast_cli_unregister_multiple(cli_iax2_provision, sizeof(cli_iax2_provision) / sizeof(struct ast_cli_entry));<br>
+ iax_provision_free_templates(0 /* Remove all templates. */);<br>
+<br>
return 0;<br>
}<br>
<br>
int iax_provision_reload(int reload)<br>
{<br>
struct ast_config *cfg;<br>
- struct iax_template *cur, *prev, *next;<br>
+ struct iax_template *cur;<br>
char *cat;<br>
int found = 0;<br>
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };<br>
@@ -495,10 +532,8 @@<br>
cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);<br>
if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {<br>
/* Mark all as dead. No need for locking */<br>
- cur = templates;<br>
- while(cur) {<br>
+ AST_LIST_TRAVERSE(&templates, cur, list) {<br>
cur->dead = 1;<br>
- cur = cur->next;<br>
}<br>
<br>
/* Load as appropriate */<br>
@@ -516,25 +551,10 @@<br>
return 0;<br>
else<br>
ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");<br>
- ast_mutex_lock(&provlock);<br>
- /* Drop dead entries while locked */<br>
- prev = NULL;<br>
- cur = templates;<br>
- while(cur) {<br>
- next = cur->next;<br>
- if (cur->dead) {<br>
- if (prev)<br>
- prev->next = next;<br>
- else<br>
- templates = next;<br>
- ast_free(cur);<br>
- } else<br>
- prev = cur;<br>
- cur = next;<br>
- }<br>
- ast_mutex_unlock(&provlock);<br>
+<br>
+ iax_provision_free_templates(1 /* remove only marked as dead */);<br>
+<br>
/* Purge cached signature DB entries */<br>
ast_db_deltree("iax/provisioning/cache", NULL);<br>
return 0;<br>
-<br>
-}<br>
+}<br>
<br>
<br>
_______________________________________________<br>
--Bandwidth and Colocation Provided by <a href="http://www.api-digital.com--" target="_blank">http://www.api-digital.com--</a><br>
<br>
asterisk-commits mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-commits" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-commits</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Eliel Sardaņons<br>