<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7041">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">RTP Engine: Deal with errors returned from AST_VECTOR_REPLACE.<br><br>Check for errors from AST_VECTOR_REPLACE and clean memory if needed.<br><br>Change-Id: I124d15cc1d645f85a72a1279f623c1993b304b0b<br>---<br>M main/rtp_engine.c<br>1 file changed, 15 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/41/7041/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/rtp_engine.c b/main/rtp_engine.c<br>index d82bc49..e703272 100644<br>--- a/main/rtp_engine.c<br>+++ b/main/rtp_engine.c<br>@@ -728,10 +728,11 @@<br>                       ao2_t_cleanup(AST_VECTOR_GET(&dest->payloads, i), "cleaning up vector element about to be replaced");<br>                }<br>             ast_debug(2, "Copying payload %d (%p) from %p to %p\n", i, type, src, dest);<br>-               ao2_bump(type);<br>-              AST_VECTOR_REPLACE(&dest->payloads, i, type);<br> <br>-              if (instance && instance->engine && instance->engine->payload_set) {<br>+                ao2_bump(type);<br>+              if (AST_VECTOR_REPLACE(&dest->payloads, i, type)) {<br>+                   ao2_cleanup(type);<br>+           } else if (instance && instance->engine && instance->engine->payload_set) {<br>                  ao2_lock(instance);<br>                   instance->engine->payload_set(instance, i, type->asterisk_format, type->format, type->rtp_code);<br>                       ao2_unlock(instance);<br>@@ -767,9 +768,10 @@<br>   if (payload < AST_VECTOR_SIZE(&codecs->payloads)) {<br>                 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, payload), "cleaning up replaced payload type");<br>      }<br>-    AST_VECTOR_REPLACE(&codecs->payloads, payload, new_type);<br> <br>-  if (instance && instance->engine && instance->engine->payload_set) {<br>+        if (AST_VECTOR_REPLACE(&codecs->payloads, payload, new_type)) {<br>+               ao2_ref(new_type, -1);<br>+       } else if (instance && instance->engine && instance->engine->payload_set) {<br>          ao2_lock(instance);<br>           instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);<br>             ao2_unlock(instance);<br>@@ -837,9 +839,10 @@<br>                   /* SDP parsing automatically increases the reference count */<br>                         new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");<br>           }<br>-            AST_VECTOR_REPLACE(&codecs->payloads, pt, new_type);<br> <br>-               if (instance && instance->engine && instance->engine->payload_set) {<br>+                if (AST_VECTOR_REPLACE(&codecs->payloads, pt, new_type)) {<br>+                    ao2_ref(new_type, -1);<br>+               } else if (instance && instance->engine && instance->engine->payload_set) {<br>                  ao2_lock(instance);<br>                   instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);<br>                  ao2_unlock(instance);<br>@@ -929,7 +932,11 @@<br>   if (payload < AST_VECTOR_SIZE(&codecs->payloads)) {<br>                 ao2_cleanup(AST_VECTOR_GET(&codecs->payloads, payload));<br>       }<br>-    AST_VECTOR_REPLACE(&codecs->payloads, payload, type);<br>+ if (AST_VECTOR_REPLACE(&codecs->payloads, payload, type)) {<br>+           ao2_ref(type, -1);<br>+           ast_rwlock_unlock(&codecs->codecs_lock);<br>+              return -1;<br>+   }<br>     ast_rwlock_unlock(&codecs->codecs_lock);<br> <br>    return 0;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7041">change 7041</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/7041"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I124d15cc1d645f85a72a1279f623c1993b304b0b </div>
<div style="display:none"> Gerrit-Change-Number: 7041 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>