diff --git a/NEWS b/NEWS index 050612214..00f309234 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ Knot Resolver 6.0.10 (202y-mm-dd) -================================ +================================= Improvements ------------ diff --git a/daemon/engine.c b/daemon/engine.c index 509915df3..a0da529be 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -741,8 +741,6 @@ int engine_register(const char *name, const char *precedence, const char* ref) if (!module) { return kr_error(ENOMEM); } - module->data = the_engine; /*< some outside modules may still use this value */ - int ret = kr_module_load(module, name, LIBDIR "/kres_modules"); if (ret == 0) { /* We have a C module, loaded and init() was called. diff --git a/lib/module.c b/lib/module.c index 79219d3a1..df9a1f5e7 100644 --- a/lib/module.c +++ b/lib/module.c @@ -103,10 +103,8 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path) return kr_error(EINVAL); } - /* Initialize, keep userdata */ - void *data = module->data; + /* Initialize */ memset(module, 0, sizeof(struct kr_module)); - module->data = data; module->name = strdup(name); if (module->name == NULL) { return kr_error(ENOMEM); @@ -123,6 +121,8 @@ int kr_module_load(struct kr_module *module, const char *name, const char *path) ret = module->init(module); } if (ret != 0) { + /* Avoid calling deinit() as init() wasn't called or failed. */ + module->deinit = NULL; kr_module_unload(module); } diff --git a/lib/module.h b/lib/module.h index 507b2df1c..4dd5a4907 100644 --- a/lib/module.h +++ b/lib/module.h @@ -86,7 +86,7 @@ struct kr_prop { /** * Load a C module instance into memory. And call its init(). * - * @param module module structure. Will be overwritten except for ->data on success. + * @param module module structure. Will be overwritten. * @param name module name * @param path module search path * @return 0 or an error diff --git a/modules/stats/stats.c b/modules/stats/stats.c index 596847d7c..09a0cfdc8 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -624,6 +624,9 @@ int stats_init(struct kr_module *module) /* Initialize ring buffer of recently visited upstreams */ array_init(data->upstreams.q); if (array_reserve(data->upstreams.q, UPSTREAMS_COUNT) != 0) { + trie_free(data->trie); + lru_free(data->queries.frequent); + free(data); return kr_error(ENOMEM); } data->upstreams.q.len = UPSTREAMS_COUNT; /* signify we use the entries */