>From e0434e676d0b3dd63a323218d207f029da9e27a4 Mon Sep 17 00:00:00 2001
From: Tim Meier <meier3@llnl.gov>
Date: Mon, 10 Nov 2008 09:48:55 -0800
Subject: [PATCH] opensm:  osm_opensm.c added a method to remove plugins

Upon shutdown, iterates through the plugins and releases
resources and removes them via their destroy() method.

Signed-off-by: Tim Meier <meier3@llnl.gov>
---
 opensm/opensm/osm_opensm.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index 7deea6d..7286782 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -238,6 +238,19 @@ static void destroy_routing_engines(osm_opensm_t *osm)
 	}
 }
 
+/**********************************************************************
+ **********************************************************************/
+static void destroy_plugins(osm_opensm_t *osm)
+{
+	osm_epi_plugin_t *p;
+	// remove from the list, and destroy it
+	while (!cl_is_qlist_empty(&osm->plugin_list)){
+		p = (osm_epi_plugin_t *)cl_qlist_remove_head(&osm->plugin_list);
+		// plugin is responsible for freeing its own resources
+		osm_epi_destroy(p);
+	}
+}
+
 void osm_opensm_destroy(IN osm_opensm_t * const p_osm)
 {
 	/* in case of shutdown through exit proc - no ^C */
@@ -275,6 +288,7 @@ void osm_opensm_destroy(IN osm_opensm_t * const p_osm)
 	osm_sa_db_file_dump(p_osm);
 
 	/* do the destruction in reverse order as init */
+	destroy_plugins(p_osm);
 	destroy_routing_engines(p_osm);
 	osm_sa_destroy(&p_osm->sa);
 	osm_sm_destroy(&p_osm->sm);
-- 
1.5.4.5

