Skip to content

Commit

Permalink
Close file handle on exceptions during connect
Browse files Browse the repository at this point in the history
Closes gh-32423
  • Loading branch information
mhalbritter committed Sep 19, 2023
1 parent 95690f7 commit 6805a33
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6805a33

Please sign in to comment.