diff --git a/src/knot/conf/base.c b/src/knot/conf/base.c index 1f1928c4d..c6d87ab28 100644 --- a/src/knot/conf/base.c +++ b/src/knot/conf/base.c @@ -27,7 +27,6 @@ #include "libknot/yparser/ypformat.h" #include "libknot/yparser/yptrafo.h" #include "contrib/files.h" -#include "contrib/mempattern.h" #include "contrib/sockaddr.h" #include "contrib/string.h" @@ -166,16 +165,8 @@ int conf_new( goto new_error; } - // Initialize a config mempool. - out->mm = malloc(sizeof(knot_mm_t)); - if (out->mm == NULL) { - ret = KNOT_ENOMEM; - goto new_error; - } - mm_ctx_init(out->mm); - // Initialize query modules list. - out->query_modules = mm_alloc(out->mm, sizeof(list_t)); + out->query_modules = malloc(sizeof(list_t)); if (out->query_modules == NULL) { ret = KNOT_ENOMEM; goto new_error; @@ -201,7 +192,7 @@ int conf_new( goto new_error; } - ret = out->api->init(&out->db, out->mm, &lmdb_opts); + ret = out->api->init(&out->db, NULL, &lmdb_opts); // Remove the database to ensure it is temporary. if (!remove_path(lmdb_opts.path)) { @@ -217,7 +208,7 @@ int conf_new( lmdb_opts.flags.env |= KNOT_DB_LMDB_RDONLY; } - ret = out->api->init(&out->db, out->mm, &lmdb_opts); + ret = out->api->init(&out->db, NULL, &lmdb_opts); } if (ret != KNOT_EOK) { goto new_error; @@ -295,11 +286,10 @@ int conf_clone( // Set shared items. out->api = s_conf->api; - out->mm = s_conf->mm; out->db = s_conf->db; // Initialize query modules list. - out->query_modules = mm_alloc(out->mm, sizeof(list_t)); + out->query_modules = malloc(sizeof(list_t)); if (out->query_modules == NULL) { yp_schema_free(out->schema); free(out); @@ -310,7 +300,7 @@ int conf_clone( // Open common read-only transaction. ret = conf_refresh_txn(out); if (ret != KNOT_EOK) { - mm_free(out->mm, out->query_modules); + free(out->query_modules); yp_schema_free(out->schema); free(out); return ret; @@ -349,7 +339,7 @@ conf_t *conf_update( conf->io.zones = s_conf->io.zones; } if ((flags & CONF_UPD_FMODULES) && s_conf != NULL) { - mm_free(conf->mm, conf->query_modules); + free(conf->query_modules); conf->query_modules = s_conf->query_modules; conf->query_plan = s_conf->query_plan; } @@ -403,16 +393,13 @@ void conf_free( conf_mod_load_purge(conf, false); conf_deactivate_modules(conf->query_modules, &conf->query_plan); - mm_free(conf->mm, conf->query_modules); + free(conf->query_modules); conf_mod_unload_shared(conf); if (!conf->is_clone) { if (conf->api != NULL) { conf->api->deinit(conf->db); } - if (conf->mm != NULL) { - free(conf->mm); - } } free(conf); diff --git a/src/knot/conf/base.h b/src/knot/conf/base.h index b47f510e4..31f307994 100644 --- a/src/knot/conf/base.h +++ b/src/knot/conf/base.h @@ -81,8 +81,6 @@ typedef struct { const struct knot_db_api *api; /*! Configuration schema. */ yp_item_t *schema; - /*! Memory context. */ - knot_mm_t *mm; /*! Configuration database. */ knot_db_t *db; diff --git a/src/knot/conf/confio.c b/src/knot/conf/confio.c index 56fe993ce..b64b27924 100644 --- a/src/knot/conf/confio.c +++ b/src/knot/conf/confio.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 CZ.NIC, z.s.p.o. +/* Copyright (C) 2018 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -824,7 +824,7 @@ static void upd_changes( // Prepare zone changes storage if it doesn't exist. trie_t *zones = conf()->io.zones; if (zones == NULL) { - zones = trie_create(conf()->mm); + zones = trie_create(NULL); if (zones == NULL) { return; } diff --git a/src/knot/conf/module.c b/src/knot/conf/module.c index 73c31fc0a..073bc067b 100644 --- a/src/knot/conf/module.c +++ b/src/knot/conf/module.c @@ -378,7 +378,7 @@ void conf_activate_modules( } // Create query plan. - *query_plan = query_plan_create(conf->mm); + *query_plan = query_plan_create(); if (*query_plan == NULL) { ret = KNOT_ENOMEM; goto activate_error; diff --git a/src/knot/nameserver/query_module.c b/src/knot/nameserver/query_module.c index 73aa384eb..26b32cea3 100644 --- a/src/knot/nameserver/query_module.c +++ b/src/knot/nameserver/query_module.c @@ -26,7 +26,6 @@ #include "knot/conf/tools.h" #include "knot/nameserver/query_module.h" #include "knot/nameserver/process_query.h" -#include "contrib/mempattern.h" #ifdef HAVE_ATOMIC #define ATOMIC_ADD(dst, val) __atomic_add_fetch(&(dst), (val), __ATOMIC_RELAXED) @@ -45,14 +44,13 @@ int knotd_conf_check_ref(knotd_conf_check_args_t *args) return check_ref(args); } -struct query_plan *query_plan_create(knot_mm_t *mm) +struct query_plan *query_plan_create(void) { - struct query_plan *plan = mm_alloc(mm, sizeof(struct query_plan)); + struct query_plan *plan = malloc(sizeof(struct query_plan)); if (plan == NULL) { return NULL; } - plan->mm = mm; for (unsigned i = 0; i < KNOTD_STAGES; ++i) { init_list(&plan->stage[i]); } @@ -69,17 +67,16 @@ void query_plan_free(struct query_plan *plan) for (unsigned i = 0; i < KNOTD_STAGES; ++i) { struct query_step *step = NULL, *next = NULL; WALK_LIST_DELSAFE(step, next, plan->stage[i]) { - mm_free(plan->mm, step); + free(step); } } - mm_free(plan->mm, plan); + free(plan); } -static struct query_step *make_step(knot_mm_t *mm, query_step_process_f process, - void *ctx) +static struct query_step *make_step(query_step_process_f process, void *ctx) { - struct query_step *step = mm_calloc(mm, 1, sizeof(struct query_step)); + struct query_step *step = calloc(1, sizeof(struct query_step)); if (step == NULL) { return NULL; } @@ -93,7 +90,7 @@ static struct query_step *make_step(knot_mm_t *mm, query_step_process_f process, int query_plan_step(struct query_plan *plan, knotd_stage_t stage, query_step_process_f process, void *ctx) { - struct query_step *step = make_step(plan->mm, process, ctx); + struct query_step *step = make_step(process, ctx); if (step == NULL) { return KNOT_ENOMEM; } diff --git a/src/knot/nameserver/query_module.h b/src/knot/nameserver/query_module.h index 0c4fdc19d..a7a224f60 100644 --- a/src/knot/nameserver/query_module.h +++ b/src/knot/nameserver/query_module.h @@ -44,12 +44,11 @@ struct query_step { * assembly phase, for example 'before processing', 'answer section' and so on. */ struct query_plan { - knot_mm_t *mm; list_t stage[KNOTD_STAGES]; }; /*! \brief Create an empty query plan. */ -struct query_plan *query_plan_create(knot_mm_t *mm); +struct query_plan *query_plan_create(void); /*! \brief Free query plan and all planned steps. */ void query_plan_free(struct query_plan *plan); diff --git a/tests/knot/test_query_module.c b/tests/knot/test_query_module.c index e77f4b765..cb4a606b3 100644 --- a/tests/knot/test_query_module.c +++ b/tests/knot/test_query_module.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 CZ.NIC, z.s.p.o. +/* Copyright (C) 2018 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +21,6 @@ #include "libknot/libknot.h" #include "knot/nameserver/query_module.h" #include "libknot/packet/pkt.h" -#include "contrib/mempattern.h" -#include "contrib/ucw/mempool.h" /* Universal processing stage. */ unsigned state_visit(unsigned state, knot_pkt_t *pkt, knotd_qdata_t *qdata, @@ -39,15 +37,11 @@ int main(int argc, char *argv[]) { plan_lazy(); - /* Create processing context. */ - knot_mm_t mm; - mm_ctx_mempool(&mm, MM_DEFAULT_BLKSIZE); - /* Create a map of expected steps. */ bool state_map[KNOTD_STAGES] = { false }; /* Prepare query plan. */ - struct query_plan *plan = query_plan_create(&mm); + struct query_plan *plan = query_plan_create(); ok(plan != NULL, "query_plan: create"); /* Register all stage visits. */ @@ -85,8 +79,5 @@ int main(int argc, char *argv[]) /* Free the query plan. */ query_plan_free(plan); - /* Cleanup. */ - mp_delete((struct mempool *)mm.ctx); - return 0; }