diff options
author | Corey Farrell <git@cfware.com> | 2017-11-06 16:30:10 -0500 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2017-11-06 16:30:10 -0500 |
commit | fc041554c315285ca17042ef4554b42d3f433cfb (patch) | |
tree | e8746cb928dd657b802ef77f1bd5856461b666d5 /main/rtp_engine.c | |
parent | ad7860fd194b69a86f43b41d6c20cdb2b653481d (diff) |
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
Diffstat (limited to 'main/rtp_engine.c')
-rw-r--r-- | main/rtp_engine.c | 23 |
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; |