diff --git a/java/src/main/java/ai/rapids/cudf/ChunkedPack.java b/java/src/main/java/ai/rapids/cudf/ChunkedPack.java index 90ec05cdbbf..d44c1322902 100644 --- a/java/src/main/java/ai/rapids/cudf/ChunkedPack.java +++ b/java/src/main/java/ai/rapids/cudf/ChunkedPack.java @@ -88,7 +88,11 @@ public PackedColumnMetadata buildMetadata() { @Override public void close() { - chunkedPackDelete(nativePtr); + try { + chunkedPackDelete(nativePtr); + } finally { + nativePtr = 0; + } } private static native long chunkedPackGetTotalContiguousSize(long nativePtr); diff --git a/java/src/main/java/ai/rapids/cudf/ColumnVector.java b/java/src/main/java/ai/rapids/cudf/ColumnVector.java index a3fca6777a2..0595d58c7cc 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnVector.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnVector.java @@ -264,6 +264,7 @@ public synchronized void close() { eventHandler.onClosed(this, refCount); } if (refCount == 0) { + super.close(); offHeap.clean(false); } else if (refCount < 0) { offHeap.logRefCountDebug("double free " + this); diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index e1da4b6a1ea..b462d70ccd2 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -6824,4 +6824,11 @@ public void testColumnViewNullCount() { assertEquals(vector.getNullCount(), view.getNullCount()); } } + + @Test + public void testUseAfterFree() { + ColumnVector vector = ColumnVector.fromBoxedInts(1, 2, 3); + vector.close(); + assertThrows(NullPointerException.class, vector::getDeviceMemorySize); + } }