Fix headerBuffer leak in DefaultEntryLogger.scanEntryLog#4023
Open
lifepuzzlefun wants to merge 2 commits intoapache:masterfrom
Open
Fix headerBuffer leak in DefaultEntryLogger.scanEntryLog#4023lifepuzzlefun wants to merge 2 commits intoapache:masterfrom
DefaultEntryLogger.scanEntryLog#4023lifepuzzlefun wants to merge 2 commits intoapache:masterfrom
Conversation
DefaultEntryLogger.scanEntryLogDefaultEntryLogger.scanEntryLog
horizonzy
reviewed
Jul 16, 2023
Member
horizonzy
left a comment
There was a problem hiding this comment.
We should also release the headerBuffer when getChannelForLogId throw exception.
Contributor
+1 |
Contributor
Author
|
Nice suggestion! The change has been committed. |
AnonHxy
reviewed
Jul 26, 2023
| bc = getChannelForLogId(entryLogId); | ||
| } catch (IOException e) { | ||
| LOG.warn("Failed to get channel to scan entry log: " + entryLogId + ".log"); | ||
| throwExceptionWhenGetChannel = true; |
Contributor
There was a problem hiding this comment.
Why not call headerBuffer.release() here?
And I think that it will be better if we move line969 to just before the second try catch block, like:
ByteBuf data = allocator.directBuffer(1024 * 1024);
ByteBuf headerBuffer = Unpooled.buffer(4 + 8); // line969
try {
// Read through the entry log file and extract the ledger ID's.
while (true) {
// Check if we'`
// ...
// ...
finally {
ReferenceCountUtil.release(headerBuffer);
ReferenceCountUtil.release(data);
}
Contributor
Author
There was a problem hiding this comment.
Thanks for review. I think the code function is the same. release resource in finally code block is more like the java style.
hangc0276
reviewed
Aug 9, 2023
Contributor
hangc0276
left a comment
There was a problem hiding this comment.
Would you please add a test to cover this change? thanks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
it should be released