Fix a potential fd leak in AbstractDiskHttpData.getChunk (#10270)
Motivation: `FileChannel.read()` may throw an IOException. We must deal with this in case of the occurrence of `I/O` error. Modification: Place the `FileChannel.read()` method call in the `try-finally` block. Result: Advoid fd leak. Co-authored-by: Norman Maurer <norman_maurer@apple.com>
This commit is contained in:
parent
9411f2a434
commit
2183b37892
@ -300,15 +300,17 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
}
|
}
|
||||||
int read = 0;
|
int read = 0;
|
||||||
ByteBuffer byteBuffer = ByteBuffer.allocate(length);
|
ByteBuffer byteBuffer = ByteBuffer.allocate(length);
|
||||||
while (read < length) {
|
try {
|
||||||
int readnow = fileChannel.read(byteBuffer);
|
while (read < length) {
|
||||||
if (readnow == -1) {
|
int readnow = fileChannel.read(byteBuffer);
|
||||||
fileChannel.close();
|
if (readnow == -1) {
|
||||||
fileChannel = null;
|
break;
|
||||||
break;
|
}
|
||||||
} else {
|
|
||||||
read += readnow;
|
read += readnow;
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
fileChannel.close();
|
||||||
|
fileChannel = null;
|
||||||
}
|
}
|
||||||
if (read == 0) {
|
if (read == 0) {
|
||||||
return EMPTY_BUFFER;
|
return EMPTY_BUFFER;
|
||||||
|
Loading…
Reference in New Issue
Block a user