summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-11-03 12:20:20 (GMT)
committerSwift Review <review@swift.im>2015-11-06 10:50:52 (GMT)
commit7302ee18a137f6810ef1cc40a395f99d2f46a644 (patch)
tree6360ffe3666118ad4e30628336c8705e240bd465 /Swiften/TLS/SecureTransport/SecureTransportCertificate.mm
parent8405fa16b738b6ef6a5920cd9d0f5735f8b62369 (diff)
downloadswift-7302ee18a137f6810ef1cc40a395f99d2f46a644.zip
swift-7302ee18a137f6810ef1cc40a395f99d2f46a644.tar.bz2
Fix potential memory leaks in Cocoa API usage
These errors were reported by Clang Analyzer. Test-Information: Verified that behavior is still as expected and Clang Analyzer does not report the warnings anymore. Change-Id: I149d75241f7680a6d2f2b6b710dd38d1ed81a209
Diffstat (limited to 'Swiften/TLS/SecureTransport/SecureTransportCertificate.mm')
-rw-r--r--Swiften/TLS/SecureTransport/SecureTransportCertificate.mm16
1 files changed, 10 insertions, 6 deletions
diff --git a/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm b/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm
index 3b4e00f..4270a6f 100644
--- a/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm
+++ b/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm
@@ -38,6 +38,7 @@ SecureTransportCertificate::SecureTransportCertificate(SecCertificateRef certifi
SecureTransportCertificate::SecureTransportCertificate(const ByteArray& der) {
CFDataRef derData = CFDataCreateWithBytesNoCopy(NULL, der.data(), static_cast<CFIndex>(der.size()), NULL);
SecCertificateRef certificate = SecCertificateCreateWithData(NULL, derData);
+ CFRelease(derData);
if (certificate) {
certificateHandle_ = boost::shared_ptr<SecCertificate>(certificate, CFRelease);
parse();
@@ -57,10 +58,7 @@ void SecureTransportCertificate::parse() {
// The SecCertificateCopyValues function is not part of the iOS Secure Transport API.
CFDictionaryRef valueDict = SecCertificateCopyValues(certificateHandle_.get(), 0, &error);
- if (error) {
- CFRelease(error);
- }
- else {
+ if (valueDict) {
// Handle subject.
CFStringRef subject = SecCertificateCopySubjectSummary(certificateHandle_.get());
if (subject) {
@@ -70,11 +68,13 @@ void SecureTransportCertificate::parse() {
}
// Handle a single Common Name.
- CFStringRef commonName;
+ CFStringRef commonName = NULL;
OSStatus error = SecCertificateCopyCommonName(certificateHandle_.get(), &commonName);
- if (!error) {
+ if (!error && commonName) {
NSString* commonNameStr = bridge_cast<NSString*>(commonName);
commonNames_.push_back(NS2STDSTRING(commonNameStr));
+ }
+ if (commonName) {
CFRelease(commonName);
}
@@ -95,6 +95,10 @@ void SecureTransportCertificate::parse() {
}
CFRelease(valueDict);
}
+
+ if (error) {
+ CFRelease(error);
+ }
}
std::string SecureTransportCertificate::getSubjectName() const {