From 6805a3393b28c1a366f8685d632386464d7da7fc Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 19 Sep 2023 15:17:14 +0200 Subject: [PATCH] Close file handle on exceptions during connect Closes gh-32423 --- .../boot/buildpack/platform/socket/DomainSocket.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java index 96f1c4f8c17..1c4e8eb2ef9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,8 +69,14 @@ public abstract class DomainSocket extends AbstractSocket { private FileDescriptor open(String path) { int handle = socket(PF_LOCAL, SOCK_STREAM, 0); - connect(path, handle); - return new FileDescriptor(handle, this::close); + try { + connect(path, handle); + return new FileDescriptor(handle, this::close); + } + catch (RuntimeException ex) { + this.close(handle); + throw ex; + } } private int read(ByteBuffer buffer) throws IOException {