From 37bcfdb0f153b2fb4f06bcdf24451d6c24e59532 Mon Sep 17 00:00:00 2001 From: Oliver Clark Rickard Date: Tue, 1 May 2018 11:15:21 -0700 Subject: [PATCH] Leak the global static mutex in CKTextKitContext to avoid static destructor fiasco Summary: OSS CK is crashing on the exit. The probable cause is that it is static mutex is destroyed at the same time when another thread tries to lock it. This diff leaks the mutex in order to avoid that crash I haven't tested this code, but this is what I would try to resolve https://github.com/facebook/componentkit/issues/892. Someone should run some smoke tests with something like the above Closes https://github.com/facebook/componentkit/pull/906 Reviewed By: kfirapps Differential Revision: D7616427 Pulled By: gkassabli fbshipit-source-id: fe4d9fc1add8228d3bd672f853cca8d54a02bc58 --- ComponentTextKit/TextKit/CKTextKitContext.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ComponentTextKit/TextKit/CKTextKitContext.mm b/ComponentTextKit/TextKit/CKTextKitContext.mm index ccf334a00..56d7b3b81 100644 --- a/ComponentTextKit/TextKit/CKTextKitContext.mm +++ b/ComponentTextKit/TextKit/CKTextKitContext.mm @@ -30,8 +30,8 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString { if (self = [super init]) { // Concurrently initialising TextKit components crashes (rdar://18448377) so we use a global lock. - static std::mutex __static_mutex; - std::lock_guard l(__static_mutex); + static std::mutex *__static_mutex = new std::mutex; + std::lock_guard l(*__static_mutex); // Create the TextKit component stack with our default configuration. _textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]); _layoutManager = layoutManagerFactory ? layoutManagerFactory() : [[NSLayoutManager alloc] init];