Skip to content

Commit

Permalink
Fix memory issue with some apps
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Apr 19, 2024
1 parent 94e79ed commit 2a3bcc7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ static void overwriteExecPath(NSString *bundlePath) {
}

// Overwrite @executable_path
*path = appBundle.executablePath.UTF8String;
const char *appExecPath = appBundle.executablePath.UTF8String;
*path = appExecPath;
overwriteExecPath(appBundle.bundlePath);

// Overwrite NSUserDefaults
Expand Down Expand Up @@ -250,6 +251,14 @@ static void overwriteExecPath(NSString *bundlePath) {
return appError;
}

if (![appBundle loadAndReturnError:&error]) {
appError = error.localizedDescription;
NSLog(@"[LCBootstrap] loading bundle failed: %@", error);
*path = oldPath;
return appError;
}
NSLog(@"[LCBootstrap] loaded bundle");

// Find main()
appMain = getAppEntryPoint(appHandle, appIndex);
if (!appMain) {
Expand All @@ -259,17 +268,9 @@ static void overwriteExecPath(NSString *bundlePath) {
return appError;
}

if (![appBundle loadAndReturnError:&error]) {
appError = error.localizedDescription;
NSLog(@"[LCBootstrap] loading bundle failed: %@", error);
*path = oldPath;
return appError;
}
NSLog(@"[LCBootstrap] loaded bundle");

// Go!
NSLog(@"[LCBootstrap] jumping to main %p", appMain);
argv[0] = (char *)NSBundle.mainBundle.executablePath.UTF8String;
argv[0] = (char *)appExecPath;
appMain(argc, argv);

return nil;
Expand Down

0 comments on commit 2a3bcc7

Please sign in to comment.