Skip to content

Commit f6b05f8

Browse files
authored
Merge pull request #790 from NativeScript/buhov/memory-leak
Fix memory leak
2 parents 1dc958e + 66f6fc0 commit f6b05f8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/NativeScript/GlobalObject.moduleLoader.mm

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
}
101101

102102
NSString* normalizePath(NSString* path) {
103-
NSArray* pathComponents = [path componentsSeparatedByString:@"/"];
103+
NSArray<NSString*>* pathComponents = [path componentsSeparatedByString:@"/"];
104104
NSMutableArray* stack = [[NSMutableArray alloc] initWithCapacity:pathComponents.count];
105105
for (NSString* pathComponent in pathComponents) {
106106
if ([pathComponent isEqualToString:@".."]) {
@@ -113,6 +113,7 @@
113113
if ([path hasPrefix:@"/"]) {
114114
result = [@"/" stringByAppendingString:result];
115115
}
116+
[stack release];
116117
return result;
117118
}
118119

@@ -247,7 +248,9 @@
247248
return deferred->reject(execState, createTypeError(execState, WTF::String::format("Unexpected module source type '%s'.", NSStringFromClass([source class]).UTF8String)));
248249
}
249250

250-
return deferred->resolve(execState, jsString(execState, contents));
251+
JSC::JSString* contentsJs = jsString(execState, contents);
252+
[contents release];
253+
return deferred->resolve(execState, contentsJs);
251254
}
252255

253256
static JSModuleRecord* parseModule(ExecState* execState, const SourceCode& sourceCode, const Identifier& moduleKey, ParserError& parserError) {
@@ -393,14 +396,14 @@
393396
args.append(moduleKey);
394397
JSValue entry = JSC::call(execState, function, callType, callData, moduleLoader, args);
395398
record = jsCast<JSModuleRecord*>(entry.get(execState, Identifier::fromString(execState, "module")));
396-
399+
397400
if (frame.check()) {
398401
NSString* moduleName = (NSString*)moduleKey.toWTFString(execState).createCFString().get();
399402
NSString* appPath = [TNSRuntime current].applicationPath;
400-
if ([moduleName hasPrefix: appPath]) {
403+
if ([moduleName hasPrefix:appPath]) {
401404
moduleName = [moduleName substringFromIndex:appPath.length];
402405
}
403-
frame.log([@"require: " stringByAppendingString: moduleName].UTF8String);
406+
frame.log([@"require: " stringByAppendingString:moduleName].UTF8String);
404407
}
405408

406409
return JSValue::encode(jsUndefined());

0 commit comments

Comments
 (0)