From 865e3633dbdc40129e2b396baa4568ede449c073 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Sat, 1 Aug 2026 18:55:08 +0200 Subject: [PATCH] fix(arrow): avoid retains on invalid chunk construction --- arrow/array/table_test.go | 4 +++- arrow/table.go | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arrow/array/table_test.go b/arrow/array/table_test.go index 08fea1a89..4720f606d 100644 --- a/arrow/array/table_test.go +++ b/arrow/array/table_test.go @@ -203,8 +203,10 @@ func TestChunkedInvalid(t *testing.T) { } }() + // Keep a valid chunk before the mismatch so failed construction must not + // leave an extra reference to it. c1 := arrow.NewChunked(arrow.PrimitiveTypes.Int32, []arrow.Array{ - f1, f2, + f2, f1, }) defer c1.Release() } diff --git a/arrow/table.go b/arrow/table.go index bdbf85bfc..4f8733502 100644 --- a/arrow/table.go +++ b/arrow/table.go @@ -146,6 +146,12 @@ type Chunked struct { // // NewChunked panics if the chunks do not have the same data type. func NewChunked(dtype DataType, chunks []Array) *Chunked { + for _, chunk := range chunks { + if chunk != nil && !TypeEqual(chunk.DataType(), dtype) { + panic(fmt.Errorf("%w: arrow/array: mismatch data type %s vs %s", ErrInvalid, chunk.DataType().String(), dtype.String())) + } + } + arr := &Chunked{ chunks: make([]Array, 0, len(chunks)), dtype: dtype, @@ -157,9 +163,6 @@ func NewChunked(dtype DataType, chunks []Array) *Chunked { continue } - if !TypeEqual(chunk.DataType(), dtype) { - panic(fmt.Errorf("%w: arrow/array: mismatch data type %s vs %s", ErrInvalid, chunk.DataType().String(), dtype.String())) - } chunk.Retain() arr.chunks = append(arr.chunks, chunk) arr.length += chunk.Len()