void dlz_destroy(void *dbdata) { if (dbdata != NULL) { ldap_instance_t *db = (ldap_instance_t *)dbdata; #if PTHREADS /* cleanup the list of DBI's */ if (db->db != NULL) ldap_destroy_dblist((db_list_t *)(db->db)); #else /* PTHREADS */ if (db->db->dbconn != NULL) ldap_unbind_s((LDAP *)(db->db->dbconn)); /* destroy single DB instance */ destroy_dbinstance(db->db); #endif /* PTHREADS */ if (db->hosts != NULL) free(db->hosts); if (db->user != NULL) free(db->user); if (db->cred != NULL) free(db->cred); free(dbdata); } }
void mysql_destroy(dbinstance_t *db) { /* release DB connection */ if (db->dbconn != NULL) mysql_close((MYSQL *) db->dbconn); /* destroy DB instance */ destroy_dbinstance(db); }
/*% * Properly cleans up a list of database instances. * This function is only used when the driver is compiled for * multithreaded operation. */ static void ldap_destroy_dblist(db_list_t *dblist) { dbinstance_t *ndbi = NULL; dbinstance_t *dbi = NULL; /* get the first DBI in the list */ ndbi = DLZ_LIST_HEAD(*dblist); /* loop through the list */ while (ndbi != NULL) { dbi = ndbi; /* get the next DBI in the list */ ndbi = DLZ_LIST_NEXT(dbi, link); /* release DB connection */ if (dbi->dbconn != NULL) ldap_unbind_s((LDAP *) dbi->dbconn); /* release all memory that comprised a DBI */ destroy_dbinstance(dbi); } /* release memory for the list structure */ free(dblist); }
/*% constructs a dbinstance (DBI) */ isc_result_t build_dbinstance(const char *allnodes_str, const char *allowxfr_str, const char *authority_str, const char *findzone_str, const char *lookup_str, const char *countzone_str, dbinstance_t **dbi, log_t log) { isc_result_t result; dbinstance_t *db = NULL; int err; /* allocate and zero memory for driver structure */ db = calloc(1, sizeof(dbinstance_t)); if (db == NULL) { if (log != NULL) log(ISC_LOG_ERROR, "Could not allocate memory for " "database instance object."); return (ISC_R_NOMEMORY); } memset(db, 0, sizeof(dbinstance_t)); db->dbconn = NULL; db->client = NULL; db->record = NULL; db->zone = NULL; db->query_buf = NULL; db->allnodes_q = NULL; db->allowxfr_q = NULL; db->authority_q = NULL; db->findzone_q = NULL; db->countzone_q = NULL; db->lookup_q = NULL; /* initialize the reference count mutex */ err = dlz_mutex_init(&db->lock, NULL); if (err == ENOMEM) { result = ISC_R_NOMEMORY; goto cleanup; } else if (err != 0) { result = ISC_R_UNEXPECTED; goto cleanup; } /* build the all nodes query list */ result = build_querylist(allnodes_str, &db->zone, &db->record, &db->client, &db->allnodes_q, REQUIRE_ZONE, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build all nodes query list"); goto cleanup; } /* build the allow zone transfer query list */ result = build_querylist(allowxfr_str, &db->zone, &db->record, &db->client, &db->allowxfr_q, REQUIRE_ZONE | REQUIRE_CLIENT, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build allow xfr query list"); goto cleanup; } /* build the authority query, query list */ result = build_querylist(authority_str, &db->zone, &db->record, &db->client, &db->authority_q, REQUIRE_ZONE, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build authority query list"); goto cleanup; } /* build findzone query, query list */ result = build_querylist(findzone_str, &db->zone, &db->record, &db->client, &db->findzone_q, REQUIRE_ZONE, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build find zone query list"); goto cleanup; } /* build countzone query, query list */ result = build_querylist(countzone_str, &db->zone, &db->record, &db->client, &db->countzone_q, REQUIRE_ZONE, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build count zone query list"); goto cleanup; } /* build lookup query, query list */ result = build_querylist(lookup_str, &db->zone, &db->record, &db->client, &db->lookup_q, REQUIRE_RECORD, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { if (log != NULL) log(ISC_LOG_ERROR, "Could not build lookup query list"); goto cleanup; } /* pass back the db instance */ *dbi = (dbinstance_t *) db; /* return success */ return (ISC_R_SUCCESS); cleanup: /* destroy whatever was build of the db instance */ destroy_dbinstance(db); /* return failure */ return (ISC_R_FAILURE); }