<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15274">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Sean Bright: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_mixmonitor: cleanup datastore when monitor thread fails to launch<br><br>launch_monitor_thread is responsible for creating and initializing<br>the mixmonitor, and dependent data structures. There was one off<br>nominal path after the datastore gets created that triggers when<br>the channel being monitored is hung up prior to monitor starting<br>itself.<br><br>If this happened the monitor thread would not "launch", and the<br>mixmonitor object and associated objects are freed, including the<br>underlying datastore data object. However, the datastore itself was<br>not removed from the channel, so when the channel eventually gets<br>destroyed it tries to access the previously freed datastore data<br>and crashes.<br><br>This patch removes and frees datastore object itself from the channel<br>before freeing the mixmonitor object thus ensuring the channel does<br>not call it when destroyed.<br><br>ASTERISK-28947 #close<br><br>Change-Id: Id4f9e958956d62473ed5ff06c98ae3436e839ff8<br>---<br>M apps/app_mixmonitor.c<br>1 file changed, 22 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c</span><br><span>index bb1bc51..239901f 100644</span><br><span>--- a/apps/app_mixmonitor.c</span><br><span>+++ b/apps/app_mixmonitor.c</span><br><span>@@ -865,6 +865,24 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void mixmonitor_ds_remove_and_free(struct ast_channel *chan, const char *datastore_id)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_datastore *datastore;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ datastore = ast_channel_datastore_find(chan, &mixmonitor_ds_info, datastore_id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Currently the one place this function is called from guarantees a</span><br><span style="color: hsl(120, 100%, 40%);">+ * datastore is present, thus return checks can be avoided here.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_datastore_remove(chan, datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_datastore_free(datastore);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int launch_monitor_thread(struct ast_channel *chan, const char *filename,</span><br><span> unsigned int flags, int readvol, int writevol,</span><br><span> const char *post_process, const char *filename_write,</span><br><span>@@ -940,7 +958,6 @@</span><br><span> pbx_builtin_setvar_helper(chan, uid_channel_var, datastore_id);</span><br><span> }</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(datastore_id);</span><br><span> </span><br><span> mixmonitor->name = ast_strdup(ast_channel_name(chan));</span><br><span> </span><br><span>@@ -990,12 +1007,16 @@</span><br><span> if (startmon(chan, &mixmonitor->audiohook)) {</span><br><span> ast_log(LOG_WARNING, "Unable to add '%s' spy to channel '%s'\n",</span><br><span> mixmonitor_spy_type, ast_channel_name(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+ mixmonitor_ds_remove_and_free(chan, datastore_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(datastore_id);</span><br><span> ast_autochan_destroy(mixmonitor->autochan);</span><br><span> ast_audiohook_destroy(&mixmonitor->audiohook);</span><br><span> mixmonitor_free(mixmonitor);</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(datastore_id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* reference be released at mixmonitor destruction */</span><br><span> mixmonitor->callid = ast_read_threadstorage_callid();</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15274">change 15274</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/+/15274"/><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: Id4f9e958956d62473ed5ff06c98ae3436e839ff8 </div>
<div style="display:none"> Gerrit-Change-Number: 15274 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@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-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>