From 5d20c3f6cfe9014ecc01100d423a4473d8143276 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 2 Jul 2020 15:19:16 -0700 Subject: [PATCH] collector: disable re-entrancy during initialization When creating a new collector, we need to prevent the following call to sysprof_malloc0() from re-entering us into the same position. --- src/libsysprof-capture/sysprof-collector.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c index 1d0c57b7..b99cd1bb 100644 --- a/src/libsysprof-capture/sysprof-collector.c +++ b/src/libsysprof-capture/sysprof-collector.c @@ -410,6 +410,12 @@ sysprof_collector_get (void) { SysprofCollector *self, *old_collector; + /* First set the collector to invalid so anything recursive + * here fails instead of becoming re-entrant. + */ + pthread_setspecific (collector_key, COLLECTOR_INVALID); + + /* Now we can malloc without ending up here again */ self = sysprof_malloc0 (sizeof (SysprofCollector)); if (self == NULL) return COLLECTOR_INVALID;