diff --git a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
index c555130097d317061e03d4428ad1aad48dd65722..a22cc425f9c174bfdbfd512832f430cf77143dca 100644
--- a/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
+++ b/openair2/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac_internal.c
@@ -934,6 +934,13 @@ int load_dl_scheduler_function(mid_t mod_id, const char *function_name) {
     LOG_I(FLEXRAN_AGENT, "Scheduler could not be loaded\n");
   }
 
+  if (flexran_agent_get_mac_xface(mod_id)) {
+    if (flexran_agent_get_mac_xface(mod_id)->dl_scheduler_loaded_lib != lib) {
+      dlclose(lib);
+    }
+  } else {
+    dlclose(lib);
+  }
   return 0;
 
  error: