You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "divijvaidya (via GitHub)" <gi...@apache.org> on 2023/04/06 10:14:18 UTC

[GitHub] [kafka] divijvaidya commented on a diff in pull request #12228: KAFKA-13950: Fix resource leak in error scenarios

divijvaidya commented on code in PR #12228:
URL: https://github.com/apache/kafka/pull/12228#discussion_r1159588380


##########
clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java:
##########
@@ -679,12 +678,13 @@ public static MemoryRecords withRecords(byte magic, long initialOffset, Compress
         long logAppendTime = RecordBatch.NO_TIMESTAMP;
         if (timestampType == TimestampType.LOG_APPEND_TIME)
             logAppendTime = System.currentTimeMillis();
-        MemoryRecordsBuilder builder = new MemoryRecordsBuilder(bufferStream, magic, compressionType, timestampType,
+        try (final MemoryRecordsBuilder builder = new MemoryRecordsBuilder(bufferStream, magic, compressionType, timestampType,

Review Comment:
   Note to reviewer(s):
   
   `builder.build()` calls the `MemoryRecordsBuilder#close()` method, hence, this is not a leak in happy cases. But it will not call `close()` in case exception occurs at `builder.append()`, hence, MemoryRecordsBuilder will not be closed when an exception is thrown.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org