[asterisk-commits] kmoore: branch group/media_formats-reviewed-trunk r418583 - /team/group/media...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 14 08:31:28 CDT 2014


Author: kmoore
Date: Mon Jul 14 08:31:17 2014
New Revision: 418583

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418583
Log:
media formats: Fix ref leak when copying ast_rtp_codecs

This ensures that rtp payload struct refs are not leaked when copying
new rtp payload structs into a position that is already occupied. This
also adds ref tags to several ref modifications of rtp payloads.

Review: https://reviewboard.asterisk.org/r/3772/

Modified:
    team/group/media_formats-reviewed-trunk/main/rtp_engine.c

Modified: team/group/media_formats-reviewed-trunk/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed-trunk/main/rtp_engine.c?view=diff&rev=418583&r1=418582&r2=418583
==============================================================================
--- team/group/media_formats-reviewed-trunk/main/rtp_engine.c (original)
+++ team/group/media_formats-reviewed-trunk/main/rtp_engine.c Mon Jul 14 08:31:17 2014
@@ -569,7 +569,7 @@
 		struct ast_rtp_payload_type *type;
 
 		type = AST_VECTOR_GET(&codecs->payloads, i);
-		ao2_cleanup(type);
+		ao2_t_cleanup(type, "destroying ast_rtp_codec");
 	}
 	AST_VECTOR_FREE(&codecs->payloads);
 
@@ -604,6 +604,9 @@
 		if (!type) {
 			continue;
 		}
+		if (i < AST_VECTOR_SIZE(&dest->payloads)) {
+			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_INSERT(&dest->payloads, i, type);
@@ -619,7 +622,6 @@
 
 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 {
-	struct ast_rtp_payload_type *old_type;
 	struct ast_rtp_payload_type *new_type;
 
 	new_type = ast_rtp_engine_alloc_payload_type();
@@ -635,10 +637,7 @@
 
 	ast_rwlock_wrlock(&codecs->codecs_lock);
 	if (payload < AST_VECTOR_SIZE(&codecs->payloads)) {
-		old_type = AST_VECTOR_GET(&codecs->payloads, payload);
-		if (old_type) {
-			ao2_ref(old_type, -1);
-		}
+		ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, payload), "cleaning up replaced payload type");
 	}
 
 	new_type->asterisk_format = static_RTP_PT[payload].asterisk_format;
@@ -675,7 +674,6 @@
 	for (i = 0; i < mime_types_len; ++i) {
 		const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];
 		struct ast_rtp_payload_type *new_type;
-		struct ast_rtp_payload_type *old_type;
 
 		if (strcasecmp(mimesubtype, t->subtype)) {
 			continue;
@@ -701,10 +699,7 @@
 		}
 
 		if (pt < AST_VECTOR_SIZE(&codecs->payloads)) {
-			old_type = AST_VECTOR_GET(&codecs->payloads, pt);
-			if (old_type) {
-				ao2_ref(old_type, -1);
-			}
+			ao2_t_cleanup(AST_VECTOR_GET(&codecs->payloads, pt), "cleaning up replaced payload type");
 		}
 
 		new_type->payload = pt;




More information about the asterisk-commits mailing list