<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14338">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, approved
Benjamin Keith Ford: Looks good to me, but someone else must approve
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">streams: Fix one memory leak and one formats ref issue<br><br>ast_stream_topology_create_from_format_cap() was setting the<br>stream->formats directly but not freeing the default formats. This<br>causes a memory leak.<br><br>* ast_stream_topology_create_from_format_cap() now calls<br> ast_stream_set_formats() which properly cleans up the existing<br> stream formats.<br><br>When cloning a stream, the source stream's format caps _pointer_ is<br>copied to the new stream and it's reference count bumped. If<br>either stream is set to "removed", this will cause _both_ streams<br>to have their format caps cleared.<br><br>* ast_stream_clone() now creates a new format caps object and copies<br> the formats from the source stream instead of just copying the<br> pointer.<br><br>ASTERISK-28870<br><br>Change-Id: If697d81c3658eb7baeea6dab413b13423938fb53<br>---<br>M main/stream.c<br>1 file changed, 9 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/stream.c b/main/stream.c</span><br><span>index 02e6a54..21dcede 100644</span><br><span>--- a/main/stream.c</span><br><span>+++ b/main/stream.c</span><br><span>@@ -137,9 +137,13 @@</span><br><span> memcpy(new_stream, stream, sizeof(*new_stream));</span><br><span> strcpy(new_stream->name, stream_name); /* Safe */</span><br><span> new_stream->group = -1;</span><br><span style="color: hsl(0, 100%, 40%);">- if (new_stream->formats) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(new_stream->formats, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ new_stream->formats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!new_stream->formats) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(new_stream);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_append_from_cap(new_stream->formats, stream->formats, AST_MEDIA_TYPE_UNKNOWN);</span><br><span> </span><br><span> new_stream->metadata = ast_stream_get_metadata_list(stream);</span><br><span> </span><br><span>@@ -585,8 +589,9 @@</span><br><span> ast_stream_topology_free(topology);</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- /* We're transferring the initial ref so no bump needed */</span><br><span style="color: hsl(0, 100%, 40%);">- stream->formats = new_cap;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_set_formats(stream, new_cap);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(new_cap, -1);</span><br><span> stream->state = AST_STREAM_STATE_SENDRECV;</span><br><span> if (ast_stream_topology_append_stream(topology, stream) == -1) {</span><br><span> ast_stream_free(stream);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14338">change 14338</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/+/14338"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: If697d81c3658eb7baeea6dab413b13423938fb53 </div>
<div style="display:none"> Gerrit-Change-Number: 14338 </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: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>