/*
  * add here other functionalities; handle their initialization
- * as appropriate in FIXME
+ * as appropriate in smbk5pwd_modules_init().
  */
 static slap_verbmasks smbk5pwd_modules[] = {
        { BER_BVC( "krb5" ),            SMBK5PWD_F_KRB5 },
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"krb5KDCEntry\" objectClass.\n",
                                0, 0, 0 );
-                       return -1;
+                       rc = -1;
+                       goto cleanup_krb5;
                }
 
                rc = slap_str2ad( "krb5Key", &ad_krb5Key, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"krb5Key\" attributeType: %s (%d).\n",
                                text, rc, 0 );
-                       return rc;
+                       goto cleanup_krb5;
                }
 
                rc = slap_str2ad( "krb5KeyVersionNumber", &ad_krb5KeyVersionNumber, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"krb5KeyVersionNumber\" attributeType: %s (%d).\n",
                                text, rc, 0 );
-                       return rc;
+                       goto cleanup_krb5;
                }
 
                rc = slap_str2ad( "krb5PrincipalName", &ad_krb5PrincipalName, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"krb5PrincipalName\" attributeType: %s (%d).\n",
                                text, rc, 0 );
-                       return rc;
+                       goto cleanup_krb5;
                }
 
                /* Initialize Kerberos context */
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to initialize krb5 context.\n",
                                0, 0, 0 );
-                       return -1;
+                       rc = -1;
+                       goto cleanup_krb5;
                }
 
                ret = kadm5_s_init_with_password_ctx( context,
                        &conf, 0, 0, &kadm_context );
        
                db = _kadm5_s_get_db(kadm_context);
+
+               if ( 0 ) {
+cleanup_krb5:;
+                       oc_krb5KDCEntry = NULL;
+
+                       return rc;
+               }
        }
 #endif /* DO_KRB5 */
 
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"sambaSamAccount\" objectClass.\n",
                                0, 0, 0 );
-                       return -1;
+                       rc = -1;
+                       goto cleanup_samba;
                }
 
                rc = slap_str2ad( "sambaLMPassword", &ad_sambaLMPassword, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"sambaLMPassword\" attributeType: %s (%d).\n",
                                text, rc, 0 );
-                       return rc;
+                       goto cleanup_samba;
                }
 
                rc = slap_str2ad( "sambaNTPassword", &ad_sambaNTPassword, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"sambaLMPassword\" attributeType: %s (%d).\n",
                                text, rc, 0 );
-                       return rc;
+                       goto cleanup_samba;
                }
 
                rc = slap_str2ad( "sambaPwdLastSet", &ad_sambaPwdLastSet, &text );
                        Debug( LDAP_DEBUG_ANY, "smbk5pwd: "
                                "unable to find \"sambaLMPassword\" attributeType: %s (%d).\n",
                                text, rc, 0 );
+                       goto cleanup_samba;
+               }
+
+               if ( 0 ) {
+cleanup_samba:;
+                       oc_sambaSamAccount = NULL;
+
                        return rc;
                }
        }