Skip to content

Commit 5245321

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Set detect_leaks=1 in various places where we do ASAN builds in CI. (#20913)
This is a relanding of #20246
1 parent 105717e commit 5245321

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

.github/workflows/build.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ jobs:
377377
scripts/run_in_build_env.sh "ninja -C ./out/$BUILD_TYPE"
378378
- name: Setup Build, Run Build and Run Tests
379379
timeout-minutes: 120
380+
# We can't enable leak checking here in LSAN_OPTIONS, because on
381+
# Darwin that's only supported with a new enough clang, and we're
382+
# not building with the pigweed clang here.
380383
run: |
381384
for BUILD_TYPE in default python_lib; do
382385
case $BUILD_TYPE in

.github/workflows/darwin-tests.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ jobs:
3232

3333
strategy:
3434
matrix:
35-
build_variant: [no-ble-asan]
35+
build_variant: [no-ble-asan-clang]
3636
env:
3737
BUILD_VARIANT: ${{matrix.build_variant}}
38+
LSAN_OPTIONS: detect_leaks=1 malloc_context_size=40 suppressions=scripts/tests/chiptest/lsan-mac-suppressions.txt
3839

3940
if: github.actor != 'restyled-io[bot]'
4041
runs-on: macos-latest

.github/workflows/tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
BUILD_VARIANT: ${{matrix.build_variant}}
3939
CHIP_TOOL_VARIANT: ${{matrix.chip_tool}}
4040
TSAN_OPTIONS: "halt_on_error=1 suppressions=scripts/tests/chiptest/tsan-linux-suppressions.txt"
41+
LSAN_OPTIONS: detect_leaks=1
4142

4243
if: github.actor != 'restyled-io[bot]'
4344
runs-on: ubuntu-latest
@@ -132,6 +133,7 @@ jobs:
132133
BUILD_VARIANT: ${{matrix.build_variant}}
133134
CHIP_TOOL_VARIANT: ${{matrix.chip_tool}}
134135
TSAN_OPTIONS: "halt_on_error=1"
136+
LSAN_OPTIONS: detect_leaks=1 suppressions=scripts/tests/chiptest/lsan-mac-suppressions.txt
135137

136138
if: github.actor != 'restyled-io[bot]'
137139
runs-on: macos-latest

examples/darwin-framework-tool/commands/common/CHIPToolKeypair.mm

+21-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ @interface CHIPToolKeypair ()
1717
@property (nonatomic) chip::Crypto::P256Keypair mIssuer;
1818
@property (nonatomic) NSData * ipk;
1919
@property (atomic) uint32_t mNow;
20+
@property (nonatomic, readonly) SecKeyRef mPublicKey;
2021
@end
2122

2223
@implementation CHIPToolKeypair
@@ -46,16 +47,19 @@ - (NSData *)signMessageECDSA_RAW:(NSData *)message
4647

4748
- (SecKeyRef)publicKey
4849
{
49-
chip::Crypto::P256PublicKey publicKey = _mKeyPair.Pubkey();
50-
NSData * publicKeyNSData = [NSData dataWithBytes:publicKey.Bytes() length:publicKey.Length()];
51-
NSDictionary * attributes = @{
52-
(__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic,
53-
(NSString *) kSecAttrKeyType : (NSString *) kSecAttrKeyTypeECSECPrimeRandom,
54-
(NSString *) kSecAttrKeySizeInBits : @Public_KeySize,
55-
(NSString *) kSecAttrLabel : kCHIPToolKeychainLabel,
56-
(NSString *) kSecAttrApplicationTag : @CHIPPlugin_CAKeyTag,
57-
};
58-
return SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, nullptr);
50+
if (_mPublicKey == nil) {
51+
chip::Crypto::P256PublicKey publicKey = _mKeyPair.Pubkey();
52+
NSData * publicKeyNSData = [NSData dataWithBytes:publicKey.Bytes() length:publicKey.Length()];
53+
NSDictionary * attributes = @{
54+
(__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic,
55+
(NSString *) kSecAttrKeyType : (NSString *) kSecAttrKeyTypeECSECPrimeRandom,
56+
(NSString *) kSecAttrKeySizeInBits : @Public_KeySize,
57+
(NSString *) kSecAttrLabel : kCHIPToolKeychainLabel,
58+
(NSString *) kSecAttrApplicationTag : @CHIPPlugin_CAKeyTag,
59+
};
60+
_mPublicKey = SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, nullptr);
61+
}
62+
return _mPublicKey;
5963
}
6064

6165
- (CHIP_ERROR)Deserialize:(chip::Crypto::P256SerializedKeypair &)input
@@ -136,4 +140,11 @@ - (CHIP_ERROR)initSerializedKeyFromValue:(NSData *)value serializedKey:(chip::Cr
136140
return CHIP_NO_ERROR;
137141
}
138142

143+
- (void)dealloc
144+
{
145+
if (_mPublicKey) {
146+
CFRelease(_mPublicKey);
147+
}
148+
}
149+
139150
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Looks like some Objective C class bits are leaked, which is probably OK since
2+
# those are singletons.
3+
leak:realizeClassWithoutSwift
4+
leak:objc_initializeClassPair_internal
5+
6+
# TODO: Under [NSManagedObjectContext executeFetchRequest] there are managed object bits that seem to be leaky.
7+
leak:class_addMethod
8+
leak:class_addIvar
9+
10+
# TODO: Leaks of blocks from dispatch source handlers that need to be investigated.
11+
leak:_Block_copy
12+
13+
# TODO: OpenSSL random byte generation creates some sort of pools that we seem to never clean up. This seems to be happening a _lot_.
14+
leak:drbg_ctr_init
15+
leak:rand_pool_new
16+
leak:RAND_priv_bytes
17+
leak:drbg_bytes
18+
19+
# TODO: OpenSSL ERR_get_state seems to leak.
20+
leak:ERR_get_state
21+
22+
# TODO: BLE initialization allocates some UUIDs and strings that seem to leak.
23+
leak:[BleConnection initWithDiscriminator:]
24+
leak:[CBXpcConnection initWithDelegate:queue:options:sessionType:]
25+
26+
# TODO: ClusterBase::SubscribeAttribute creates a subscription that cannot
27+
# actually be shut down in any way.
28+
leak:ClusterBase::SubscribeAttribute
29+
30+
# TODO: Figure out how we are managing to leak NSData while using ARC!
31+
leak:[CHIPToolKeypair signMessageECDSA_RAW:]
32+
33+
# TODO: Figure out how we are managing to leak NSData while using ARC, though
34+
# this may just be a leak deep inside the CFPreferences stuff somewhere.
35+
leak:[CHIPToolPersistentStorageDelegate storageDataForKey:]

0 commit comments

Comments
 (0)