diff --git a/src/darwin/Framework/CHIP/MTRCertificates.mm b/src/darwin/Framework/CHIP/MTRCertificates.mm index 140dd5deb41aae..7dcec96cba695b 100644 --- a/src/darwin/Framework/CHIP/MTRCertificates.mm +++ b/src/darwin/Framework/CHIP/MTRCertificates.mm @@ -158,8 +158,9 @@ + (BOOL)keypair:(id)keypair matchesCertificate:(NSData *)certificate publicKey = [keypair copyPublicKey]; } else { publicKey = [keypair publicKey]; - if (publicKey) + if (publicKey) { CFRetain(publicKey); + } } CHIP_ERROR err = MTRP256KeypairBridge::MatterPubKeyFromSecKeyRef(publicKey, &keypairPubKey); diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 026beb279c4de3..e287ef0446593f 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -825,8 +825,9 @@ - (BOOL)findMatchingFabric:(FabricTable &)fabricTable publicKey = [params.nocSigner copyPublicKey]; } else { publicKey = [params.nocSigner publicKey]; - if (publicKey) + if (publicKey) { CFRetain(publicKey); + } } CHIP_ERROR err = MTRP256KeypairBridge::MatterPubKeyFromSecKeyRef(publicKey, &pubKey);