Fix memory leaks when using generate_appcast (#2193)

We fix one memory leak when calculating sha's, one memory leak in the xar delta applying path, and avoid creating Bundles for reading the Sparkle framework version.

There are some other small leaks with the xar delta creation/applying code but since it's a legacy implementation and the APIs are undocumented I don't want to touch it too much.

The biggest culprit here is the leak when calculating sha's I believe, if you have many archive items.
This commit is contained in:
Zorg authored and GitHub committed 2022-07-09 12:22:36 -07:00
1 parent 80e60279ee
commit 14e511f901
3 files changed
+24 -10

No files matched your search

+5 -1
View File
@@ -348,7 +348,11 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
continue;
}
NSString *relativePath = @(pathCString);
NSString *relativePath = [[NSString alloc] initWithBytesNoCopy:pathCString length:strlen(pathCString) encoding:NSUTF8StringEncoding freeWhenDone:YES];
if (relativePath == nil) {
free(pathCString);
continue;
}
SPUDeltaItemCommands commands = 0;
{
+15 -9
View File
@@ -138,18 +138,24 @@ class ArchiveItem: CustomStringConvertible {
}
var frameworkVersion: String? = nil
if let appBundle = Bundle(url: appPath), let frameworksURL = appBundle.privateFrameworksURL {
let sparkleBundleURL = frameworksURL.appendingPathComponent("Sparkle").appendingPathExtension("framework")
do {
let canonicalFrameworksURL = appPath.appendingPathComponent("Contents/Frameworks/Sparkle.framework")
if let sparkleBundle = Bundle(url: sparkleBundleURL), let infoDictionary = sparkleBundle.infoDictionary {
frameworkVersion = infoDictionary[kCFBundleVersionKey as String] as? String
} else {
let frameworksURL: URL?
if !FileManager.default.fileExists(atPath: canonicalFrameworksURL.path) {
// Try legacy SparkleCore framework that was shipping in early 2.0 betas
let sparkleCoreBundleURL = frameworksURL.appendingPathComponent("SparkleCore").appendingPathExtension("framework")
if let sparkleBundle = Bundle(url: sparkleCoreBundleURL), let infoDictionary = sparkleBundle.infoDictionary {
frameworkVersion = infoDictionary[kCFBundleVersionKey as String] as? String
let sparkleCoreFrameworksURL = appPath.appendingPathComponent("Contents/Frameworks/SparkleCore.framework")
if FileManager.default.fileExists(atPath: sparkleCoreFrameworksURL.path) {
frameworksURL = sparkleCoreFrameworksURL
} else {
frameworksURL = nil
}
} else {
frameworksURL = canonicalFrameworksURL
}
if let frameworksURL = frameworksURL, let frameworkInfoPlist = NSDictionary(contentsOf: frameworksURL.appendingPathComponent("Resources/Info.plist")) {
frameworkVersion = frameworkInfoPlist[kCFBundleVersionKey as String] as? String
}
}
+4
View File
@@ -33,6 +33,10 @@ extension FileHandle {
CC_SHA256_Final(hash.baseAddress, &context)
defer {
hash.deallocate()
}
return hash.reduce("") { $0 + String(format: "%02x", $1) }
}