Skip to content

Commit

Permalink
apacheGH-36981: [Go] Fix ipc reader leak (apache#36982)
Browse files Browse the repository at this point in the history
### Rationale for this change

Previously the ipc reader was leaking allocations.

### What changes are included in this PR?

Call `Clear()` on the memo table on final release of the ipc reader.

### Are these changes tested?

Yes

### Are there any user-facing changes?

* Closes: apache#36981

Authored-by: thorfour <me@thor-hansen.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
  • Loading branch information
thorfour committed Aug 1, 2023
1 parent 0fb744c commit f44e28f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/arrow/ipc/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (r *Reader) Release() {
r.r.Release()
r.r = nil
}
r.memo.Clear()
}
}

Expand Down
37 changes: 37 additions & 0 deletions go/arrow/ipc/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,40 @@ func TestReaderCatchPanic(t *testing.T) {
assert.Contains(t, err.Error(), "arrow/ipc: unknown error while reading")
}
}

func TestReaderCheckedAllocator(t *testing.T) {
alloc := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer alloc.AssertSize(t, 0)
schema := arrow.NewSchema([]arrow.Field{
{
Name: "s",
Type: &arrow.DictionaryType{
ValueType: arrow.BinaryTypes.String,
IndexType: arrow.PrimitiveTypes.Int32,
},
},
}, nil)

b := array.NewRecordBuilder(alloc, schema)
defer b.Release()

bldr := b.Field(0).(*array.BinaryDictionaryBuilder)
bldr.Append([]byte("foo"))
bldr.Append([]byte("bar"))
bldr.Append([]byte("baz"))

rec := b.NewRecord()
defer rec.Release()

buf := new(bytes.Buffer)
writer := NewWriter(buf, WithSchema(schema), WithAllocator(alloc))
defer writer.Close()
require.NoError(t, writer.Write(rec))

reader, err := NewReader(buf, WithAllocator(alloc))
require.NoError(t, err)
defer reader.Release()

_, err = reader.Read()
require.NoError(t, err)
}

0 comments on commit f44e28f

Please sign in to comment.