Skip to content

Commit

Permalink
Fix leaked cookieMap in RCTJSCExecutor
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D3207245

fb-gh-sync-id: 1263974e2f94175cd4bf190cec446b88b5273aca
fbshipit-source-id: 1263974e2f94175cd4bf190cec446b88b5273aca
  • Loading branch information
alexeylang authored and Facebook Github Bot 8 committed Apr 22, 2016
1 parent 8b1726b commit 32a8949
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions React/Executors/RCTJSCExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ @implementation RCTJSCExecutor
{
RCTJavaScriptContext *_context;
NSThread *_javaScriptThread;
CFMutableDictionaryRef _cookieMap;

FILE *_bundle;
JSStringRef _bundleURL;
Expand Down Expand Up @@ -347,16 +348,24 @@ - (void)setUp
[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){
Expand Down Expand Up @@ -467,6 +476,10 @@ - (void)dealloc
CFRelease(_jsModules);
fclose(_bundle);
}

if (_cookieMap) {
CFRelease(_cookieMap);
}
}

- (void)flushedQueue:(RCTJavaScriptCallback)onComplete
Expand Down

0 comments on commit 32a8949

Please sign in to comment.