Skip to content

Commit

Permalink
Merge pull request #24 from Liftric/fix/memory-leaks
Browse files Browse the repository at this point in the history
Fix memory leaks
  • Loading branch information
gaebel authored Jun 10, 2021
2 parents fea0687 + 046f83b commit f5e9d41
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions kvault/src/iosMain/kotlin/com/liftric/kvault/KVault.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ actual open class KVault(
* If the bundle identifier is nil, it will fallback to `com.liftric.KVault`.
*/
@Deprecated("Will be removed in a future version, please use the primary constructor. Check your service name before migrating.")
constructor(): this(Constants.BundleIdentifier, null)
constructor() : this(Constants.BundleIdentifier, null)

// ===============
// SET OPERATIONS
Expand Down Expand Up @@ -255,7 +255,6 @@ actual open class KVault(
CFDictionaryAddValue(query, kSecClass, kSecClassGenericPassword)
CFDictionaryAddValue(query, kSecAttrAccount, CFBridgingRetain(key))
CFDictionaryAddValue(query, kSecValueData, CFBridgingRetain(value))

return if (existsObject(key)) {
update(value, key)
} else {
Expand All @@ -269,14 +268,12 @@ actual open class KVault(
CFDictionaryAddValue(query, kSecAttrAccount, CFBridgingRetain(forKey))
CFDictionaryAddValue(query, kSecReturnData, kCFBooleanTrue)
CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitOne)

memScoped {
val result = alloc<CFTypeRefVar>()
if (perform(Operation.Get, query, result)) {
return CFBridgingRelease(result.value) as NSData
}
}

return null
}

Expand Down Expand Up @@ -315,6 +312,8 @@ actual open class KVault(
Operation.Update -> SecItemUpdate(query, updateQuery)
Operation.Delete -> SecItemDelete(query)
}
CFRelease(query)
updateQuery?.let { CFRelease(it) }

return if (status.toUInt() == noErr) {
true
Expand Down

0 comments on commit f5e9d41

Please sign in to comment.