<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7085">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: Fix multiple leaks.<br><br>* Pre-initialize vectors to final size in<br> ast_sip_session_media_state_clone to ensure errors cannot happen later<br> in the function.<br>* Release session_media on vector replace failure in<br> ast_sip_session_media_state_add.<br>* Release clone and media_state in ast_sip_session_refresh if we fail to<br> append to the stream topology, return an error.<br><br>Change-Id: Ib5ffc9b198683fa7e9bf166d74d30c1334c23acb<br>---<br>M res/res_pjsip_session.c<br>1 file changed, 20 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/85/7085/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c<br>index 4724d46..f557fee 100644<br>--- a/res/res_pjsip_session.c<br>+++ b/res/res_pjsip_session.c<br>@@ -238,6 +238,16 @@<br> }<br> }<br> <br>+ if (AST_VECTOR_INIT(&cloned->sessions, AST_VECTOR_SIZE(&media_state->sessions))) {<br>+ ast_sip_session_media_state_free(cloned);<br>+ return NULL;<br>+ }<br>+<br>+ if (AST_VECTOR_INIT(&cloned->read_callbacks, AST_VECTOR_SIZE(&media_state->read_callbacks))) {<br>+ ast_sip_session_media_state_free(cloned);<br>+ return NULL;<br>+ }<br>+<br> for (index = 0; index < AST_VECTOR_SIZE(&media_state->sessions); ++index) {<br> struct ast_sip_session_media *session_media = AST_VECTOR_GET(&media_state->sessions, index);<br> enum ast_media_type type = ast_stream_get_type(ast_stream_topology_get_stream(cloned->topology, index));<br>@@ -452,7 +462,11 @@<br> }<br> }<br> <br>- AST_VECTOR_REPLACE(&media_state->sessions, position, session_media);<br>+ if (AST_VECTOR_REPLACE(&media_state->sessions, position, session_media)) {<br>+ ao2_ref(session_media, -1);<br>+<br>+ return NULL;<br>+ }<br> <br> /* If this stream will be active in some way and it is the first of this type then consider this the default media session to match */<br> if (!media_state->default_session[type] && ast_stream_get_state(ast_stream_topology_get_stream(media_state->topology, position)) != AST_STREAM_STATE_REMOVED) {<br>@@ -1588,7 +1602,11 @@<br> }<br> <br> ast_stream_set_state(cloned, AST_STREAM_STATE_REMOVED);<br>- ast_stream_topology_append_stream(media_state->topology, cloned);<br>+ if (ast_stream_topology_append_stream(media_state->topology, cloned)) {<br>+ ast_stream_free(cloned);<br>+ ast_sip_session_media_state_free(media_state);<br>+ return -1;<br>+ }<br> }<br> <br> /* If the resulting media state matches the existing active state don't bother doing a session refresh */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7085">change 7085</a>. To unsubscribe, 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/7085"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib5ffc9b198683fa7e9bf166d74d30c1334c23acb </div>
<div style="display:none"> Gerrit-Change-Number: 7085 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>