ast_format_cap: Avoid format creation on module load, use cache instead.
authorAlexander Traud <pabstraud@compuserve.com>
Mon, 9 Nov 2015 13:04:43 +0000 (14:04 +0100)
committerAlexander Traud <pabstraud@compuserve.com>
Mon, 9 Nov 2015 13:05:14 +0000 (14:05 +0100)
Since Asterisk 13, formats are immutable and cached. However while loading a
module like chan_sip, some formats were created instead using cached ones.

ASTERISK-25535 #close

Change-Id: I479cdc220d5617c840a98f3389b3bd91e91fbd9b

main/format_cap.c

index d486d5d..2221c53 100644 (file)
@@ -230,7 +230,10 @@ int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_typ
                        continue;
                }
 
-               format = ast_format_create(codec);
+               format = ast_format_cache_get(codec->name);
+               if (!format || (codec != ast_format_get_codec(format))) {
+                       format = ast_format_create(codec);
+               }
                ao2_ref(codec, -1);
 
                if (!format) {