Skip to content

Commit c75b877

Browse files
committed
fix(jni): release the schema export in VortexWriter.build()
build() closed the exported ArrowSchema without calling its release callback. Native code only borrows the schema, so the child structs the export allocated were never freed, and every writer's allocator closed with outstanding memory. Signed-off-by: gitRasheed <[email protected]>
1 parent 1459236 commit c75b877

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎java/vortex-jni/src/main/java/dev/vortex/api/VortexWriter.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public VortexWriter build() throws IOException {
165165
}
166166
return new VortexWriter(pointer);
167167
} finally {
168+
// Native code only borrows the schema, so the children the export allocated are ours to release.
169+
if (ffi.snapshot().release != 0) {
170+
ffi.release();
171+
}
168172
ffi.close();
169173
}
170174
}

‎java/vortex-jni/src/test/java/dev/vortex/jni/JNIWriterTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.arrow.c.ArrowSchema;
3131
import org.apache.arrow.c.Data;
3232
import org.apache.arrow.memory.BufferAllocator;
33+
import org.apache.arrow.memory.RootAllocator;
3334
import org.apache.arrow.vector.BigIntVector;
3435
import org.apache.arrow.vector.IntVector;
3536
import org.apache.arrow.vector.VarBinaryVector;
@@ -169,6 +170,18 @@ public void testCreateWriter() throws IOException {
169170
source.arrowSchema(allocator));
170171
}
171172

173+
@Test
174+
public void testCreateWriterReleasesSchemaExport() throws IOException {
175+
String writePath = tempDir.resolve("test_schema_release.vortex").toUri().toString();
176+
Session session = Session.create();
177+
try (BufferAllocator allocator = new RootAllocator()) {
178+
try (VortexWriter writer = VortexWriter.builder(session, writePath, personSchema(), allocator)
179+
.build()) {
180+
assertEquals(0, allocator.getAllocatedMemory());
181+
}
182+
}
183+
}
184+
172185
@Test
173186
public void testCreateWriterPlainLocalPath() throws IOException {
174187
Path outputPath = tempDir.resolve("test_create_plain_path.vortex");

0 commit comments

Comments
 (0)