diff --git a/res/res_smdi.c b/res/res_smdi.c
index 7b4c42b176ceca75fe4d1d04f96239bb4b4f6ec5..49d10cc555bbd49b65c90a97b993defdb50e2025 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -1379,6 +1379,9 @@ static int load_module(void)
 	ast_custom_function_register(&smdi_msg_retrieve_function);
 	ast_custom_function_register(&smdi_msg_function);
 
+	/* For Optional API. */
+	ast_module_shutdown_ref(ast_module_info->self);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -1408,9 +1411,6 @@ static int _unload_module(int fromload)
 
 	smdi_loaded = 0;
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(ast_module_info->self);
-
 	return 0;
 }