<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19720">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: 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;">streams:  Ensure that stream is closed in ast_stream_and_wait on error<br><br>When ast_stream_and_wait returns an error (for example, when attempting<br>to stream to a channel after hangup) the stream is not closed, and<br>callers typically do not check the return code. This results in leaking<br>file descriptors, leading to resource exhaustion.<br><br>This change ensures that the stream is closed in case of error.<br><br>ASTERISK-30198 #close<br>Reported-by: Julien Alie<br><br>Change-Id: Ie46b67314590ad75154595a3d34d461060b2e803<br>---<br>M include/asterisk/file.h<br>M main/file.c<br>2 files changed, 24 insertions(+), 0 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/file.h b/include/asterisk/file.h</span><br><span>index 4e7c505..4fade8e 100644</span><br><span>--- a/include/asterisk/file.h</span><br><span>+++ b/include/asterisk/file.h</span><br><span>@@ -80,6 +80,7 @@</span><br><span>  * \brief stream file until digit</span><br><span>  * If the file name is non-empty, try to play it.</span><br><span>  * \note If digits == "" then we can simply check for non-zero.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note If a failure is encountered, the stream will be closed before returning.</span><br><span>  * \retval 0 if success.</span><br><span>  * \retval -1 if error.</span><br><span>  * \retval digit if interrupted by a digit.</span><br><span>diff --git a/main/file.c b/main/file.c</span><br><span>index 972f234..d7c7543 100644</span><br><span>--- a/main/file.c</span><br><span>+++ b/main/file.c</span><br><span>@@ -1862,6 +1862,10 @@</span><br><span>                       res = ast_waitstream(chan, digits);</span><br><span>          }</span><br><span>    }</span><br><span style="color: hsl(120, 100%, 40%);">+     if (res == -1) {</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_stopstream(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  return res;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19720">change 19720</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/+/19720"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Ie46b67314590ad75154595a3d34d461060b2e803 </div>
<div style="display:none"> Gerrit-Change-Number: 19720 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Peter Fern <asterisk@obfusc8.org> </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-MessageType: merged </div>