awslabs / aws-sdk-swift

Apache License 2.0
399 stars 79 forks source link

Possible memory leaks #599

Open brennanMKE opened 2 years ago

brennanMKE commented 2 years ago

Description

The log at the bottom was collected with the Leaks profiler in Instruments. There appears to be memory accumulating while an app is working.

Context

Environment

Xcode, macOS running on macOS (latest release versions)

Reproduction Steps

Run an app which uses the code listed in the log.

Observed Behavior

Memory appears to accumulate.

Expected Behavior

Memory should level out after work is done.

Possible Solution

There may be memory allocations which are acquired but not always released in the Swift CRT integration.

leaks.log ``` s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 specialized CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/auth/credentials/CRTCredentials.swift:24 CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/:0 $s19AwsCommonRuntimeKit14CRTCredentialsC9accessKey6secret12sessionToken17expirationTimeout9allocatorACSS_S2SSgs6UInt64VAA9Allocator_ptcfC /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 $s16AWSClientRuntime14AWSCredentialsV9toCRTType09AwsCommonB3Kit14CRTCredentialsCyF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/AWSCredentials.swift:26 $s16AWSClientRuntime29CredentialsProviderCRTAdapterV03getC009AwsCommonB3Kit14CRTCredentialsCyYaKF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift:25 (1) await resume partial function for protocol witness for CRTCredentialsProvider.getCredentials() in conformance CredentialsProviderCRTAdapter /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 specialized CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/auth/credentials/CRTCredentials.swift:24 CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/:0 $s19AwsCommonRuntimeKit14CRTCredentialsC9accessKey6secret12sessionToken17expirationTimeout9allocatorACSS_S2SSgs6UInt64VAA9Allocator_ptcfC /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 $s16AWSClientRuntime14AWSCredentialsV9toCRTType09AwsCommonB3Kit14CRTCredentialsCyF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/AWSCredentials.swift:26 AWSSigningConfig.toCRTType() /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 (1) await resume partial function for SigV4Middleware.handle(context:input:next:) /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit11HttpHeadersC3add4name5valueSbSS_SStF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeaders.swift:30 HttpHeaders.addArray(headers:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeaders.swift:40 $s13ClientRuntime21SdkHttpRequestBuilderC022convertSignedHeadersToI003crtE0AA0I0V09AwsCommonB3Kit0dE0C_tF /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/SdkHttpRequest.swift:73 (2) await resume partial function for SigV4Middleware.handle(context:input:next:) /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 SigningConfig.init(credentials:credentialsProvider:date:service:region:expiration:signedBodyHeader:signedBodyValue:flags:shouldSignHeader:signatureType:signingAlgorithm:configType:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/auth/signing/SigningConfig.swift:52 AWSSigningConfig.toCRTType() /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 (1) await resume partial function for SigV4Middleware.handle(context:input:next:) /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 specialized CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/auth/credentials/CRTCredentials.swift:24 CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/:0 $s19AwsCommonRuntimeKit14CRTCredentialsC9accessKey6secret12sessionToken17expirationTimeout9allocatorACSS_S2SSgs6UInt64VAA9Allocator_ptcfC /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 $s16AWSClientRuntime14AWSCredentialsV9toCRTType09AwsCommonB3Kit14CRTCredentialsCyF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/AWSCredentials.swift:26 $s16AWSClientRuntime29CredentialsProviderCRTAdapterV03getC009AwsCommonB3Kit14CRTCredentialsCyYaKF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift:25 (1) await resume partial function for protocol witness for CRTCredentialsProvider.getCredentials() in conformance CredentialsProviderCRTAdapter /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit10HttpHeaderV4name5value11compressionACSS_SSAA0eF11CompressionOtcfC /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeader.swift:23 specialized closure #2 in HttpClientConnection.makeRequest(requestOptions:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpClientConnection.swift:68 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit10HttpHeaderV4name5value11compressionACSS_SSAA0eF11CompressionOtcfC /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeader.swift:23 HttpHeaders.getAll() /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeaders.swift:85 specialized Headers.init(httpHeaders:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/Headers.swift:205 $s13ClientRuntime7HeadersV04httpC0AC09AwsCommonB3Kit04HttpC0C_tcfC /ROOT/PROJECT/Local/smithy-swift/:0 $s13ClientRuntime21SdkHttpRequestBuilderC022convertSignedHeadersToI003crtE0AA0I0V09AwsCommonB3Kit0dE0C_tF /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/SdkHttpRequest.swift:75 SdkHttpRequestBuilder.update(from:originalRequest:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/SdkHttpRequest.swift:61 (2) await resume partial function for SigV4Middleware.handle(context:input:next:) /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit10HttpHeaderV4name5value11compressionACSS_SSAA0eF11CompressionOtcfC /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeader.swift:23 HttpMessage.addHeaders(headers:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpMessage.swift:48 specialized SdkHttpRequest.toHttpRequest(bufferSize:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/SdkHttpRequest.swift:34 $s13ClientRuntime14SdkHttpRequestC02todE010bufferSize09AwsCommonB3Kit0dE0CSi_tF /ROOT/PROJECT/Local/smithy-swift/:0 CRTClientEngine.makeHttpRequestStreamOptions(_:_:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/CRT/CRTClientEngine.swift:110 closure #1 in CRTClientEngine.execute(request:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/CRT/CRTClientEngine.swift:96 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit10HttpHeaderV4name5value11compressionACSS_SSAA0eF11CompressionOtcfC /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeader.swift:23 HttpHeaders.getAll() /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeaders.swift:85 Headers.addAll(httpHeaders:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/Headers.swift:212 closure #1 in CRTClientEngine.makeHttpRequestStreamOptions(_:_:) /ROOT/PROJECT/Local/smithy-swift/Packages/ClientRuntime/Sources/Networking/Http/CRT/CRTClientEngine.swift:115 specialized closure #2 in HttpClientConnection.makeRequest(requestOptions:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpClientConnection.swift:68 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 $s19AwsCommonRuntimeKit10HttpHeaderV4name5value11compressionACSS_SSAA0eF11CompressionOtcfC /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpHeader.swift:24 specialized closure #2 in HttpClientConnection.makeRequest(requestOptions:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/http/HttpClientConnection.swift:68 s_default_malloc /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:54 aws_mem_acquire /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/allocator.c:126 aws_string_new_from_array /ROOT/PROJECT/Local/aws-crt-swift/aws-common-runtime/aws-c-common/source/string.c:196 $sSS19AwsCommonRuntimeKitE6asCStrSPys4Int8VGSgyF /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/crt/AWSString.swift:47 $sSS19AwsCommonRuntimeKitE13awsByteCursorSo0E12_byte_cursorVvg /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/Utilities.swift:27 specialized CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/Source/AwsCommonRuntimeKit/auth/credentials/CRTCredentials.swift:24 CRTCredentials.init(accessKey:secret:sessionToken:expirationTimeout:allocator:) /ROOT/PROJECT/Local/aws-crt-swift/:0 $s19AwsCommonRuntimeKit14CRTCredentialsC9accessKey6secret12sessionToken17expirationTimeout9allocatorACSS_S2SSgs6UInt64VAA9Allocator_ptcfC /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 $s16AWSClientRuntime14AWSCredentialsV9toCRTType09AwsCommonB3Kit14CRTCredentialsCyF /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/AWSClientRuntime/Sources/Auth/AWSCredentials.swift:26 AWSSigningConfig.toCRTType() /ROOT/Library/Developer/Xcode/DerivedData/Storage-aihphthgszdlsydovtyoarbyeekc/SourcePackages/checkouts/aws-sdk-swift/:0 ```
AndyMeagher commented 1 year ago

Any update on this? I am seeing Memory Allocation crashes that appear to stem from the aws-crt-swift package.