Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/hx/libs/ssl/SSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,17 @@ Dynamic _hx_ssl_cert_load_defaults(){
if( SecKeychainOpen("/System/Library/Keychains/SystemRootCertificates.keychain",&keychain) != errSecSuccess )
return null();

// Search for certificates
// Search for certificates. Every CF object created or copied here is
// released: this runs for every TLS connection, and the matching array
// alone holds the whole system root store (hundreds of KB).
Comment on lines +560 to +562

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Search for certificates. Every CF object created or copied here is
// released: this runs for every TLS connection, and the matching array
// alone holds the whole system root store (hundreds of KB).
// Search for certificates
// Make sure to release anything we allocate

I think it is self explanatory why we should not leak objects, so a short reminder should be enough

search = CFDictionaryCreateMutable( NULL, 0, NULL, NULL );
CFArrayRef searchList = CFArrayCreate(NULL, (const void **)&keychain, 1, NULL);
CFDictionarySetValue( search, kSecClass, kSecClassCertificate );
CFDictionarySetValue( search, kSecMatchLimit, kSecMatchLimitAll );
CFDictionarySetValue( search, kSecReturnRef, kCFBooleanTrue );
CFDictionarySetValue( search, kSecMatchSearchList, CFArrayCreate(NULL, (const void **)&keychain, 1, NULL) );
if( SecItemCopyMatching( search, (CFTypeRef *)&result ) == errSecSuccess ){
CFDictionarySetValue( search, kSecMatchSearchList, searchList );
result = NULL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be initialised to NULL at the declaration?

if( SecItemCopyMatching( search, (CFTypeRef *)&result ) == errSecSuccess && result ){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where it would return errSecSuccess but give a null result?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that, but I'd say it doesn't harm testing it

CFIndex n = CFArrayGetCount( result );
for( CFIndex i = 0; i < n; i++ ){
item = (SecCertificateRef)CFArrayGetValueAtIndex( result, i );
Expand All @@ -580,6 +584,9 @@ Dynamic _hx_ssl_cert_load_defaults(){
}
}
}
if( result ) CFRelease( result );
CFRelease( search );
CFRelease( searchList );
CFRelease(keychain);
if( chain != NULL )
return chain;
Expand Down
Loading