summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-30 23:19:44 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2021-07-16 18:40:00 +0200
commit46e595cb26bb62c43a87b15d9eb30e5e56b17519 (patch)
tree8cce1d869644cfc285ef6f158c1de761ba903604
parent41126d256aa1e35cf2631e11d6e9545ba1a9c01e (diff)
downloadNetworkManager-46e595cb26bb62c43a87b15d9eb30e5e56b17519.tar.gz
platform: fix releasing thead-local stack of NMPNetns instances
Fixes: 12df49f8ab45 ('platform: make NMPNetns thread-safe') (cherry picked from commit b433c21ae47949329c973c0a58d6df16068bf629) (cherry picked from commit 724ef83e062ccceda4b7f41ce386850982a4fe8a)
-rw-r--r--shared/nm-platform/nmp-netns.c10
1 files changed, 1 insertions, 9 deletions
diff --git a/shared/nm-platform/nmp-netns.c b/shared/nm-platform/nmp-netns.c
index f97339a756..4dd9e8487a 100644
--- a/shared/nm-platform/nmp-netns.c
+++ b/shared/nm-platform/nmp-netns.c
@@ -11,7 +11,6 @@
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <pthread.h>
#include "nm-log-core/nm-logging.h"
@@ -151,20 +150,13 @@ _netns_stack_get_impl(void)
{
gs_unref_object NMPNetns *netns = NULL;
gs_free_error GError *error = NULL;
- pthread_key_t key;
GArray * s;
s = g_array_new(FALSE, FALSE, sizeof(NetnsInfo));
g_array_set_clear_func(s, _netns_stack_clear_cb);
_netns_stack = s;
- /* register a destructor function to cleanup the array. If we fail
- * to do so, we will leak NMPNetns instances (and their file descriptor) when the
- * thread exits. */
- if (pthread_key_create(&key, (void (*)(void *)) g_array_unref) != 0)
- _LOGE(NULL, "failure to initialize thread-local storage");
- else if (pthread_setspecific(key, s) != 0)
- _LOGE(NULL, "failure to set thread-local storage");
+ nm_utils_thread_local_register_destroy(s, (GDestroyNotify) g_array_unref);
/* at the bottom of the stack we must try to create a netns instance
* that we never pop. It's the base to which we need to return. */