summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2024-12-20 14:41:48 +0100
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-12-20 14:41:48 +0100
commitec0d46fd0e214ec8f007c946379ad0db844a8f51 (patch)
treebd7f957f02e603a12fb1be2cb2ed96c7c432a01c
parentMerge !1450: manager: subprocess debugging via GDB (diff)
parentNEWS nit: avoid a Sphinx warning (diff)
downloadknot-resolver-ec0d46fd0e214ec8f007c946379ad0db844a8f51.tar.xz
knot-resolver-ec0d46fd0e214ec8f007c946379ad0db844a8f51.zip
Merge !1643: kr_module_load(): clean up the code a bit
-rw-r--r--NEWS2
-rw-r--r--daemon/engine.c2
-rw-r--r--lib/module.c6
-rw-r--r--lib/module.h2
-rw-r--r--modules/stats/stats.c3
5 files changed, 8 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 05061221..00f30923 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 509915df..a0da529b 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 79219d3a..df9a1f5e 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 507b2df1..4dd5a490 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 596847d7..09a0cfdc 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 */