Skip to content

Commit 4c2983c

Browse files
authored
fix(array): add nil checks in Data.Release() for childData (#456)
### Rationale for this change My program crashed with below log ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x53beb92] goroutine 294 [running]: github.com/apache/arrow-go/v18/arrow/array.(*Data).Release(0xc02586a5b0) /root/go/pkg/mod/github.com/apache/arrow-go/v18@v18.4.0/arrow/array/data.go:150 +0x172 github.com/apache/arrow-go/v18/arrow/array.concat.func1() /root/go/pkg/mod/github.com/apache/arrow-go/v18@v18.4.0/arrow/array/concat.go:528 +0x9c github.com/apache/arrow-go/v18/arrow/array.concat({0xc14ae66008, 0x100, 0x100}, {0x83213c0, 0xb026080}) /root/go/pkg/mod/github.com/apache/arrow-go/v18@v18.4.0/arrow/array/concat.go:652 +0x3f7d github.com/apache/arrow-go/v18/arrow/array.Concatenate({0xc104861908, 0x100, 0x12f}, {0x83213c0, 0xb026080}) /root/go/pkg/mod/github.com/apache/arrow-go/v18@v18.4.0/arrow/array/concat.go:55 +0x585 ... ``` ### What changes are included in this PR? Add nil check in Data.Release() for childData to avoid crash. ### Are these changes tested? Yes. ### Are there any user-facing changes? No.
1 parent 21a20e3 commit 4c2983c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

arrow/array/data.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ func (d *Data) Release() {
147147
}
148148

149149
for _, b := range d.childData {
150-
b.Release()
150+
if b != nil {
151+
b.Release()
152+
}
151153
}
152154

153155
if d.dictionary != nil {

arrow/array/data_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,22 @@ func TestSizeInBytes(t *testing.T) {
136136
}
137137
})
138138
}
139+
140+
func TestDataReleaseWithNilChildData(t *testing.T) {
141+
mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
142+
defer mem.AssertSize(t, 0)
143+
144+
// Create a Data object that simulates the state after a failed concatenation
145+
// where childData slice is allocated but contains nil elements
146+
buffers := []*memory.Buffer{memory.NewBufferBytes([]byte("test-buffer"))}
147+
data := NewData(arrow.ListOf(arrow.PrimitiveTypes.Int32), 1, buffers, nil, 0, 0)
148+
149+
// Simulate the scenario where childData is allocated but elements remain nil
150+
// This happens in concat.go when childData is allocated but concat() fails
151+
data.childData = make([]arrow.ArrayData, 1)
152+
// data.childData[0] remains nil (simulating failed concat)
153+
154+
assert.NotPanics(t, func() {
155+
data.Release()
156+
}, "Release() should not panic when childData contains nil elements")
157+
}

0 commit comments

Comments
 (0)