Skip to content

Commit c66582f

Browse files
waahm7praetp
andauthored
Fix tls_ctx memleak in s3 client creation (#824)
Co-authored-by: Paul Praet <3198728+praetp@users.noreply.github.com>
1 parent 9861cd7 commit c66582f

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

crt/s2n

Submodule s2n updated from 79c0f1b to 87f4a05

src/native/s3_client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew(
521521
env, &proxy_options, jni_proxy_host, jni_proxy_authorization_username, jni_proxy_authorization_password);
522522

523523
aws_mem_release(aws_jni_get_allocator(), s3_tcp_keep_alive_options);
524-
524+
if (tls_options) {
525+
aws_tls_connection_options_clean_up(tls_options);
526+
}
525527
return (jlong)client;
526528
}
527529

src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ public void testS3ClientCreateDestroy() {
126126

127127
}
128128
}
129+
130+
@Test
131+
public void testS3ClientCreateDestroyWithTLS() {
132+
skipIfAndroid();
133+
skipIfNetworkUnavailable();
134+
135+
try (TlsContextOptions tlsContextOptions = TlsContextOptions.createDefaultClient();
136+
TlsContext tlsContext = new TlsContext(tlsContextOptions);) {
137+
S3ClientOptions clientOptions = new S3ClientOptions()
138+
.withRegion(REGION)
139+
.withTlsContext(tlsContext);
140+
try (S3Client client = createS3Client(clientOptions)) {
141+
}
142+
}
143+
}
129144

130145
@Test
131146
public void testS3ClientCreateDestroyWithCredentialsProvider() {
@@ -260,8 +275,9 @@ public void testS3ClientCreateDestroyHttpProxyOptions() {
260275
proxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic);
261276
proxyOptions.setAuthorizationUsername("username");
262277
proxyOptions.setAuthorizationPassword("password");
263-
try (S3Client client = createS3Client(new S3ClientOptions().withRegion(REGION)
264-
.withProxyOptions(proxyOptions), elg)) {
278+
try (S3Client client = createS3Client(new S3ClientOptions()
279+
.withRegion(REGION)
280+
.withProxyOptions(proxyOptions), elg)) {
265281
}
266282
}
267283
}

0 commit comments

Comments
 (0)