From 32a89493fb953aa1046fc92ade831c0aebf29c6e Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Fri, 22 Apr 2016 06:43:52 -0700 Subject: [PATCH] Fix leaked cookieMap in RCTJSCExecutor Reviewed By: javache Differential Revision: D3207245 fb-gh-sync-id: 1263974e2f94175cd4bf190cec446b88b5273aca fbshipit-source-id: 1263974e2f94175cd4bf190cec446b88b5273aca --- React/Executors/RCTJSCExecutor.mm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/React/Executors/RCTJSCExecutor.mm b/React/Executors/RCTJSCExecutor.mm index 6d17699b7..6fcf19018 100644 --- a/React/Executors/RCTJSCExecutor.mm +++ b/React/Executors/RCTJSCExecutor.mm @@ -110,6 +110,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) { RCTJavaScriptContext *_context; NSThread *_javaScriptThread; + CFMutableDictionaryRef _cookieMap; FILE *_bundle; JSStringRef _bundleURL; @@ -347,16 +348,24 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context) [self addSynchronousHookWithName:@"__RCTProfileIsProfiling" usingBlock:@YES]; } - CFMutableDictionaryRef cookieMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); + _cookieMap = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); [self addSynchronousHookWithName:@"nativeTraceBeginAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) { + RCTJSCExecutor *strongSelf = weakSelf; + if (!strongSelf) { + return; + } NSUInteger newCookie = RCTProfileBeginAsyncEvent(tag, name, nil); - CFDictionarySetValue(cookieMap, (const void *)cookie, (const void *)newCookie); + CFDictionarySetValue(strongSelf->_cookieMap, (const void *)cookie, (const void *)newCookie); }]; [self addSynchronousHookWithName:@"nativeTraceEndAsyncSection" usingBlock:^(uint64_t tag, NSString *name, NSUInteger cookie) { - NSUInteger newCookie = (NSUInteger)CFDictionaryGetValue(cookieMap, (const void *)cookie); + RCTJSCExecutor *strongSelf = weakSelf; + if (!strongSelf) { + return; + } + NSUInteger newCookie = (NSUInteger)CFDictionaryGetValue(strongSelf->_cookieMap, (const void *)cookie); RCTProfileEndAsyncEvent(tag, @"js,async", newCookie, name, @"JS async", nil); - CFDictionaryRemoveValue(cookieMap, (const void *)cookie); + CFDictionaryRemoveValue(strongSelf->_cookieMap, (const void *)cookie); }]; [self addSynchronousHookWithName:@"nativeTraceBeginSection" usingBlock:^(NSNumber *tag, NSString *profileName){ @@ -467,6 +476,10 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context) CFRelease(_jsModules); fclose(_bundle); } + + if (_cookieMap) { + CFRelease(_cookieMap); + } } - (void)flushedQueue:(RCTJavaScriptCallback)onComplete