From 94121a1b48b67ede0ebe8dec336da18e05d403eb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jun 2021 23:56:26 +0200 Subject: [PATCH] glib-aux: avoid accessing thread-local variable in a loop Dunno whether the compiler can optimize this out. Assign to an auto variable. --- src/libnm-glib-aux/nm-random-utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-random-utils.c b/src/libnm-glib-aux/nm-random-utils.c index 8c364cb543..f622b28411 100644 --- a/src/libnm-glib-aux/nm-random-utils.c +++ b/src/libnm-glib-aux/nm-random-utils.c @@ -203,7 +203,8 @@ fd_open: } if (!urandom_success) { - static _nm_thread_local GRand *rand = NULL; + static _nm_thread_local GRand *rand_tls = NULL; + GRand * rand; gsize i; int j; @@ -214,8 +215,10 @@ fd_open: */ has_high_quality = FALSE; + rand = rand_tls; if (G_UNLIKELY(!rand)) { - rand = _rand_create_thread_local(); + rand = _rand_create_thread_local(); + rand_tls = rand; nm_utils_thread_local_register_destroy(rand, (GDestroyNotify) g_rand_free); }