From 48c78fc91e3897c85a7279e8bbf6e89f157f96e2 Mon Sep 17 00:00:00 2001 From: Hannes Rantzsch Date: Thu, 2 Jan 2020 17:36:19 +0700 Subject: [PATCH] check for errors before CFRelease (#20) macOS' SecKeychainFindGenericPassword can return a non-NULL item pointer even if the function fails (because the item is not found). In this case we must not try to CFRelease the item, or we'll segfault. --- keychain_mac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keychain_mac.cpp b/keychain_mac.cpp index 52e5095..19a1157 100644 --- a/keychain_mac.cpp +++ b/keychain_mac.cpp @@ -221,7 +221,7 @@ void deletePassword(const std::string &package, const std::string &service, } } - if (item) { + if (!err && item) { CFRelease(item); }