From cd619a5c92308c7e4ffbfc07329dd86c5c4694e0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jun 2021 23:19:44 +0200 Subject: [PATCH] glib-aux: fix releasing thead-local GRand instance from nm_utils_random_bytes() Fixes: b01a453ca298 ('core: add nm_utils_random_bytes() and use getrandom()') (cherry picked from commit c127e1beccfd468b2b2bfcca2e7cb1d952068e17) (cherry picked from commit 3de83dd25c96e41156194805f45677a59c280c81) --- shared/nm-glib-aux/nm-random-utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/nm-random-utils.c b/shared/nm-glib-aux/nm-random-utils.c index c95d368dd3..97272ca31c 100644 --- a/shared/nm-glib-aux/nm-random-utils.c +++ b/shared/nm-glib-aux/nm-random-utils.c @@ -122,8 +122,10 @@ fd_open: */ has_high_quality = FALSE; - if (G_UNLIKELY(!rand)) + if (G_UNLIKELY(!rand)) { rand = g_rand_new(); + nm_utils_thread_local_register_destroy(rand, (GDestroyNotify) g_rand_free); + } nm_assert(n > 0); i = 0;