From dac1fbe3d35bf5e78320c4402718628866ed9d0a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Sep 2023 14:36:17 +0200 Subject: libnftables: move init-once guard inside xt_init() A library should not restrict being used by multiple threads or make assumptions about how it's being used. Hence a "init_once" pattern without no locking is racy, a code smell and should be avoided. Note that libxtables is full of global variables and when linking against it, libnftables cannot be used from multiple threads either. That is not easy to fix. Move the ugliness of "init_once" away from nft_ctx_new(), so that the problem is concentrated closer to libxtables. Signed-off-by: Thomas Haller Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/libnftables.c') diff --git a/src/libnftables.c b/src/libnftables.c index cedd710b..1ca5a6f4 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -191,15 +191,11 @@ void nft_ctx_clear_include_paths(struct nft_ctx *ctx) EXPORT_SYMBOL(nft_ctx_new); struct nft_ctx *nft_ctx_new(uint32_t flags) { - static bool init_once; struct nft_ctx *ctx; - if (!init_once) { - init_once = true; #ifdef HAVE_LIBXTABLES - xt_init(); + xt_init(); #endif - } ctx = xzalloc(sizeof(struct nft_ctx)); nft_init(ctx); -- cgit v1.2.3