[Asterisk-code-review] RTP Engine: Deal with errors returned from AST VECTOR REPLACE. (asterisk[13])

Jenkins2 asteriskteam at digium.com
Tue Nov 7 06:06:02 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7041 )

Change subject: RTP Engine: Deal with errors returned from AST_VECTOR_REPLACE.
......................................................................

RTP Engine: Deal with errors returned from AST_VECTOR_REPLACE.

Check for errors from AST_VECTOR_REPLACE and clean memory if needed.

Change-Id: I124d15cc1d645f85a72a1279f623c1993b304b0b
---
M main/rtp_engine.c
1 file changed, 15 insertions(+), 8 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index d82bc49..e703272 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -728,10 +728,11 @@
 			ao2_t_cleanup(AST_VECTOR_GET(&dest->payloads, i), "cleaning up vector element about to be replaced");
 		}
 		ast_debug(2, "Copying payload %d (%p) from %p to %p\n", i, type, src, dest);
-		ao2_bump(type);
-		AST_VECTOR_REPLACE(&dest->payloads, i, type);
 
-		if (instance && instance->engine && instance->engine->payload_set) {
+		ao2_bump(type);
+		if (AST_VECTOR_REPLACE(&dest->payloads, i, type)) {
+			ao2_cleanup(type);
+		} else if (instance && instance->engine && instance->engine->payload_set) {
 			ao2_lock(instance);
 			instance->engine->payload_set(instance, i, type->asterisk_format, type->format, type->rtp_code);
 			ao2_unlock(instance);
@@ -767,9 +768,10 @@
 	if (payload < AST_VECTOR_SIZE(&codecs->payloads)) {
 		ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, payload), "cleaning up replaced payload type");
 	}
-	AST_VECTOR_REPLACE(&codecs->payloads, payload, new_type);
 
-	if (instance && instance->engine && instance->engine->payload_set) {
+	if (AST_VECTOR_REPLACE(&codecs->payloads, payload, new_type)) {
+		ao2_ref(new_type, -1);
+	} else if (instance && instance->engine && instance->engine->payload_set) {
 		ao2_lock(instance);
 		instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
 		ao2_unlock(instance);
@@ -837,9 +839,10 @@
 			/* SDP parsing automatically increases the reference count */
 			new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");
 		}
-		AST_VECTOR_REPLACE(&codecs->payloads, pt, new_type);
 
-		if (instance && instance->engine && instance->engine->payload_set) {
+		if (AST_VECTOR_REPLACE(&codecs->payloads, pt, new_type)) {
+			ao2_ref(new_type, -1);
+		} else if (instance && instance->engine && instance->engine->payload_set) {
 			ao2_lock(instance);
 			instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
 			ao2_unlock(instance);
@@ -929,7 +932,11 @@
 	if (payload < AST_VECTOR_SIZE(&codecs->payloads)) {
 		ao2_cleanup(AST_VECTOR_GET(&codecs->payloads, payload));
 	}
-	AST_VECTOR_REPLACE(&codecs->payloads, payload, type);
+	if (AST_VECTOR_REPLACE(&codecs->payloads, payload, type)) {
+		ao2_ref(type, -1);
+		ast_rwlock_unlock(&codecs->codecs_lock);
+		return -1;
+	}
 	ast_rwlock_unlock(&codecs->codecs_lock);
 
 	return 0;

-- 
To view, visit https://gerrit.asterisk.org/7041
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I124d15cc1d645f85a72a1279f623c1993b304b0b
Gerrit-Change-Number: 7041
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171107/5e3b7849/attachment-0001.html>


More information about the asterisk-code-review mailing list