Repository navigation
Release the keychain objects of the certificate lookup on macOS (fix memory leak) #1424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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). | ||
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ){ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ); | ||
|
|
@@ -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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is self explanatory why we should not leak objects, so a short reminder should be enough