<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16092">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><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;"><span>diff --git a/funcs/func_lock.c b/funcs/func_lock.c</span><br><span>index ad4d58e..f64011f 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>@@ -449,9 +448,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(¤t->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(¤t->cond, ¤t->mutex);</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16092">change 16092</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/+/16092"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Id19ba3d9867b23d0e6783b97e6ecd8e62698b8c3 </div>
<div style="display:none"> Gerrit-Change-Number: 16092 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-CC: Jaco Kroon <jaco@uls.co.za> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>