On unload, free up g_mechSet and g_mechList
authorKen Raeburn <raeburn@mit.edu>
Fri, 2 Mar 2007 05:30:30 +0000 (05:30 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 2 Mar 2007 05:30:30 +0000 (05:30 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19201 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/gssapi/mechglue/g_initialize.c

index 0c4513cacdb134676ce1fd16cf9a5a0fcce49f0e..d948b98d125de22dca40d5cf40a9c93dc917e59e 100644 (file)
 /* Local functions */
 static gss_mech_info searchMechList(const gss_OID);
 static void updateMechList(void);
+static void freeMechList(void);
 static void register_mech(gss_mechanism, const char *, void *);
 
 static OM_uint32 build_mechSet(void);
+static void free_mechSet(void);
 static void init_hardcoded(void);
 
 /*
@@ -74,6 +76,8 @@ gssint_mechglue_fini(void)
 {
        k5_mutex_destroy(&g_mechSetLock);
        k5_mutex_destroy(&g_mechListLock);
+       free_mechSet();
+       freeMechList();
 }
 
 
@@ -219,6 +223,21 @@ gss_OID_set *mechSet;
 } /* gss_indicate_mechs */
 
 
+/* Call with g_mechSetLock held, or during final cleanup.  */
+static void
+free_mechSet(void)
+{
+       int i;
+
+       if (g_mechSet.count != 0) {
+               for (i = 0; i < g_mechSet.count; i++)
+                       free(g_mechSet.elements[i].elements);
+               free(g_mechSet.elements);
+               g_mechSet.elements = NULL;
+               g_mechSet.count = 0;
+       }
+}
+
 static OM_uint32
 build_mechSet(void)
 {
@@ -244,13 +263,7 @@ build_mechSet(void)
        (void) k5_mutex_lock(&g_mechSetLock);
 
        /* if the oid list already exists we must free it first */
-       if (g_mechSet.count != 0) {
-               for (i = 0; i < g_mechSet.count; i++)
-                       free(g_mechSet.elements[i].elements);
-               free(g_mechSet.elements);
-               g_mechSet.elements = NULL;
-               g_mechSet.count = 0;
-       }
+       free_mechSet();
 
        /* determine how many elements to have in the list */
        mList = g_mechList;
@@ -453,6 +466,19 @@ updateMechList(void)
 
 } /* updateMechList */
 
+static void
+freeMechList(void)
+{
+       gss_mech_info cf, next_cf;
+
+       for (cf = g_mechList; cf != NULL; cf = next_cf) {
+               next_cf = cf->next;
+               free(cf->uLibName);
+               free(cf->mechNameStr);
+               free(cf);
+       }
+}
+
 /*
  * Register a mechanism.  Called with g_mechListLock held.
  */