Senrian opened a new pull request, #10231:
URL: https://github.com/apache/rocketmq/pull/10231
## Bug Description
In `DumpCompactionLogCommand.java`, a `RandomAccessFile` is created to
obtain a `FileChannel`, but neither the `RandomAccessFile` nor the
`FileChannel` is ever closed. This causes a file descriptor leak.
**Issue:** #10218
```java
// Before (buggy):
FileChannel fileChannel = new RandomAccessFile(fileName, "rw").getChannel();
ByteBuffer buf = fileChannel.map(MapMode.READ_WRITE, 0, fileSize);
// ...
UtilAll.cleanBuffer(buf);
// fileChannel and RandomAccessFile are never closed
```
## Fix
Use try-with-resources to ensure both `RandomAccessFile` and `FileChannel`
are properly closed:
```java
try (RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
FileChannel fileChannel = raf.getChannel()) {
// ...
}
```
This follows the recommended Java practice for resource management.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]