sezruby commented on code in PR #1492:
URL: https://github.com/apache/arrow-java/pull/1492#discussion_r4617735897
##########
c/src/main/java/org/apache/arrow/c/ArrowArrayStreamReader.java:
##########
@@ -64,7 +64,16 @@ public boolean loadNextBatch() throws IOException {
if (array.snapshot().release == NULL) {
return false;
}
- Data.importIntoVectorSchemaRoot(allocator, array, getVectorSchemaRoot(),
provider);
+ try {
+ Data.importIntoVectorSchemaRoot(allocator, array,
getVectorSchemaRoot(), provider);
+ } catch (Throwable t) {
+ // If the import failed before moving the batch out of the array, e.g.
allocating the
+ // schema, the batch is still in the array: release it.
+ if (array.snapshot().release != NULL) {
+ array.release();
+ }
+ throw t;
+ }
Review Comment:
Thanks, good catch. Applied in 2d037af4: the import now passes
`closeImportedStructs = false`, so the array stays open for the failure
handling and the enclosing try-with-resources closes it once. A failure
releasing the batch is added to the original exception as suppressed.
I didn't add a test for this path because I couldn't find an input that
fails after the import closes the array. `ArrayImporter.importBuffers` loads
the buffers into the vectors before the array is closed, including allocating a
missing validity bitmap. After that, unloading the struct and loading the root
only retain the imported buffers. `setReaderAndWriterIndex` allocates only when
the offset buffer holds fewer than length + 1 offsets, and the importer rejects
such a buffer. So the allocator-limit sweep in the stream test doesn't reach
this path.
--
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]