diff --git a/res/res_smdi.c b/res/res_smdi.c
index 1dc9cbe5daccb41270dda0e5200557f7d4fa2b3b..5288bbee53705f667ffcd2aed6cdd5d945a87a66 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -1407,6 +1407,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;
 }
 
@@ -1436,9 +1439,6 @@ static int _unload_module(int fromload)
 
 	smdi_loaded = 0;
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(ast_module_info->self);
-
 	return 0;
 }