summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2017-11-07 06:06:01 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-11-07 06:06:01 -0600
commit36b5a66c27582e0b54d5dababec93f78fc272f73 (patch)
treeb0b7e13b46448012dfd7018cde62d0523016c9e6
parentb96dd55add67b124b39c722639fb56e53f6ee61b (diff)
parentfc041554c315285ca17042ef4554b42d3f433cfb (diff)
Merge "RTP Engine: Deal with errors returned from AST_VECTOR_REPLACE." into 13
-rw-r--r--main/rtp_engine.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index d82bc4980..e7032724b 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -728,10 +728,11 @@ void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_cod
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 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as
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 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs,
/* 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 @@ int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int pay
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;