From 981084f08cd2b696f9f0009e71020302c078b828 Mon Sep 17 00:00:00 2001
From: Corey Farrell <git@cfware.com>
Date: Sun, 3 May 2015 22:03:13 -0400
Subject: [PATCH] Format Interfaces: Prevent unload except by shutdown.

Format interfaces cannot be unregistered, so the modules that provide them
need to be held open except by shutdown.

ASTERISK-25054 #close
Reported by: Corey Farrell

Change-Id: Iadbd9675bf0d30b8fded5a739b163db3ea2db8f3
---
 main/format.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/main/format.c b/main/format.c
index 8fed71f734..bbfb697216 100644
--- a/main/format.c
+++ b/main/format.c
@@ -36,6 +36,7 @@ ASTERISK_REGISTER_FILE()
 #include "asterisk/format.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/strings.h"
+#include "asterisk/module.h"
 
 /*! \brief Number of buckets to use for format interfaces (should be prime for performance reasons) */
 #define FORMAT_INTERFACE_BUCKETS 53
@@ -156,6 +157,8 @@ int __ast_format_interface_register(const char *codec, const struct ast_format_i
 	format_interface->interface = interface;
 	strcpy(format_interface->codec, codec); /* Safe */
 
+	/* Once registered a format interface cannot be unregistered. */
+	ast_module_shutdown_ref(mod);
 	ao2_link_flags(interfaces, format_interface, OBJ_NOLOCK);
 	ao2_ref(format_interface, -1);
 
-- 
GitLab