<p>Jaco Kroon <strong>uploaded patch set #2</strong> to this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15945">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_lock: Prevent module unloading in-use module.<br><br>The scenario where a channel still has an associated datastore we<br>cannot unload since there is a function pointer to the destroy and fixup<br>functions in play.  Thus increase the module ref count whenever we<br>allocate a datastore, and decrease it during destroy.<br><br>In order to tighten the race that still exists in spite of this (below)<br>add some extra failure cases to prevent allocations in these cases.<br><br>Race:<br><br>If module ref is zero, an LOCK or TRYLOCK is invoked (near)<br>simultaneously on a channel that has NOT PREVIOUSLY taken a lock, and if<br>in such a case the datastore is created *prior* to unloading being set<br>to true (first step in module unload) then it's possible that the module<br>will unload with the destructor being called (and segfault) post the<br>module being unloaded.  The module will however wait for such locks to<br>release prior to unloading.<br><br>If post that we can recheck the module ref before returning the we can<br>(in theory, I think) eliminate the last of the race.  This race is<br>mostly theoretical in nature.<br><br>Change-Id: I21a514a0b56755c578a687f4867eacb8b59e23cf<br>Signed-off-by: Jaco Kroon <jaco@uls.co.za><br>---<br>M funcs/func_lock.c<br>1 file changed, 14 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/45/15945/2</pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15945">change 15945</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/+/15945"/><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: I21a514a0b56755c578a687f4867eacb8b59e23cf </div>
<div style="display:none"> Gerrit-Change-Number: 15945 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Jaco Kroon <jaco@uls.co.za> </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-MessageType: newpatchset </div>