From c66582f404572ee0b46e4bc2d1b98ff0c6ca2dfe Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Fri, 23 Aug 2024 14:38:41 -0700 Subject: [PATCH] Fix tls_ctx memleak in s3 client creation (#824) Co-authored-by: Paul Praet <3198728+praetp@users.noreply.github.com> --- crt/aws-c-compression | 2 +- crt/s2n | 2 +- src/native/s3_client.c | 4 +++- .../amazon/awssdk/crt/test/S3ClientTest.java | 20 +++++++++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/crt/aws-c-compression b/crt/aws-c-compression index ea1d421a4..f36d01672 160000 --- a/crt/aws-c-compression +++ b/crt/aws-c-compression @@ -1 +1 @@ -Subproject commit ea1d421a421ad83a540309a94c38d50b6a5d836b +Subproject commit f36d01672d61e49d96a777870d456f66fa391cd4 diff --git a/crt/s2n b/crt/s2n index 79c0f1b43..87f4a0585 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit 79c0f1b434742d9f1152c48d3781433649f6f8fe +Subproject commit 87f4a0585dc3056433f193b9305f587cff239be3 diff --git a/src/native/s3_client.c b/src/native/s3_client.c index 09d516f53..6d19db0bf 100644 --- a/src/native/s3_client.c +++ b/src/native/s3_client.c @@ -521,7 +521,9 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew( env, &proxy_options, jni_proxy_host, jni_proxy_authorization_username, jni_proxy_authorization_password); aws_mem_release(aws_jni_get_allocator(), s3_tcp_keep_alive_options); - + if (tls_options) { + aws_tls_connection_options_clean_up(tls_options); + } return (jlong)client; } diff --git a/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java b/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java index 1622181f5..8fd141f58 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java @@ -126,6 +126,21 @@ public void testS3ClientCreateDestroy() { } } + + @Test + public void testS3ClientCreateDestroyWithTLS() { + skipIfAndroid(); + skipIfNetworkUnavailable(); + + try (TlsContextOptions tlsContextOptions = TlsContextOptions.createDefaultClient(); + TlsContext tlsContext = new TlsContext(tlsContextOptions);) { + S3ClientOptions clientOptions = new S3ClientOptions() + .withRegion(REGION) + .withTlsContext(tlsContext); + try (S3Client client = createS3Client(clientOptions)) { + } + } + } @Test public void testS3ClientCreateDestroyWithCredentialsProvider() { @@ -260,8 +275,9 @@ public void testS3ClientCreateDestroyHttpProxyOptions() { proxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic); proxyOptions.setAuthorizationUsername("username"); proxyOptions.setAuthorizationPassword("password"); - try (S3Client client = createS3Client(new S3ClientOptions().withRegion(REGION) - .withProxyOptions(proxyOptions), elg)) { + try (S3Client client = createS3Client(new S3ClientOptions() + .withRegion(REGION) + .withProxyOptions(proxyOptions), elg)) { } } }