From 2f4f21602661bdefc99bc5dd4ea61ca58c40ca1f Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Mon, 6 Nov 2017 16:20:06 -0500 Subject: 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 --- main/rtp_engine.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 0aed8e97c..2431ffc0c 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -802,7 +802,10 @@ static void rtp_codecs_payload_replace_rx(struct ast_rtp_codecs *codecs, int pay ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_rx, payload), "cleaning up rx mapping vector element about to be replaced"); } - AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type); + if (AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type)) { + ao2_ref(new_type, -1); + return; + } payload_mapping_rx_clear_primary(codecs, new_type); } @@ -924,7 +927,10 @@ static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_r ao2_t_cleanup(AST_VECTOR_GET(&dest->payload_mapping_tx, idx), "cleaning up tx mapping vector element about to be replaced"); } - AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type); + if (AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type)) { + ao2_ref(type, -1); + continue; + } if (instance && instance->engine && instance->engine->payload_set) { ao2_lock(instance); @@ -1038,9 +1044,10 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload), "cleaning up replaced tx payload type"); } - AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type); - if (instance && instance->engine && instance->engine->payload_set) { + if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, 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); @@ -1116,9 +1123,10 @@ int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt), "cleaning up replaced tx payload type"); } - AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type); - if (instance && instance->engine && instance->engine->payload_set) { + if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, 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); @@ -1215,7 +1223,9 @@ int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int pay if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) { ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload)); } - AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type); + if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) { + ao2_ref(type, -1); + } } else { ao2_ref(type, -1); } -- cgit v1.2.3