<p>Jaco Kroon has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15943">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_lock: Fix memory corruption during unload.<br><br>AST_TRAVERSE accessess current as current = current->(field).next ...<br>and since we free current (and ast_free poisons the memory) we either<br>end up on a ast_mutex_lock to a non-existing lock that can never be<br>obtained, or a segfault.<br><br>Incidentally add logging in the "we have to wait for a lock to release"<br>case, and remove an ineffective statement that sets memory that was just<br>cleared by ast_calloc to zero.<br><br>Change-Id: Id19ba3d9867b23d0e6783b97e6ecd8e62698b8c3<br>Signed-off-by: Jaco Kroon <jaco@uls.co.za><br>---<br>M funcs/func_lock.c<br>1 file changed, 8 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/43/15943/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_lock.c b/funcs/func_lock.c</span><br><span>index 0726407..9932232 100644</span><br><span>--- a/funcs/func_lock.c</span><br><span>+++ b/funcs/func_lock.c</span><br><span>@@ -249,7 +249,6 @@</span><br><span>                         AST_LIST_UNLOCK(&locklist);</span><br><span>                      return -1;</span><br><span>           }</span><br><span style="color: hsl(0, 100%, 40%);">-               current->requesters = 0;</span><br><span>          AST_LIST_INSERT_TAIL(&locklist, current, entries);</span><br><span>       }</span><br><span>    /* Add to requester list */</span><br><span>@@ -440,9 +439,16 @@</span><br><span>   ast_custom_function_unregister(&trylock_function);</span><br><span> </span><br><span>   AST_LIST_LOCK(&locklist);</span><br><span style="color: hsl(0, 100%, 40%);">-   AST_LIST_TRAVERSE(&locklist, current, entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+  while ((current = AST_LIST_REMOVE_HEAD(&locklist, entries))) {</span><br><span style="color: hsl(120, 100%, 40%);">+            int warned = 0;</span><br><span>              ast_mutex_lock(&current->mutex);</span><br><span>              while (current->owner || current->requesters) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 if (!warned) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                ast_log(LOG_WARNING, "Waiting for %d requesters for %s lock %s.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                         current->requesters, current->owner ? "locked" : "unlocked",</span><br><span style="color: hsl(120, 100%, 40%);">+                                                current->name);</span><br><span style="color: hsl(120, 100%, 40%);">+                            warned = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+                   }</span><br><span>                    /* either the mutex is locked, or other parties are currently in get_lock,</span><br><span>                    * we need to wait for all of those to clear first */</span><br><span>                        ast_cond_wait(&current->cond, &current->mutex);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15943">change 15943</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15943"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Id19ba3d9867b23d0e6783b97e6ecd8e62698b8c3 </div>
<div style="display:none"> Gerrit-Change-Number: 15943 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jaco Kroon <jaco@uls.co.za> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>