Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
// https://github.com/dolthub/dolt/issues/9987
Name: "GROUP BY nil pointer dereference in Dispose when Next() never called",
SetUpScript: []string{
"CREATE TABLE test_table (id INT PRIMARY KEY, value INT, category VARCHAR(50))",
"INSERT INTO test_table VALUES (1, 100, 'A'), (2, 200, 'B'), (3, 300, 'A')",
},
Assertions: []ScriptTestAssertion{
{
// LIMIT 0 causes the iterator to close without ever calling Next() on groupByIter
// This leaves all buffer elements as nil causing panic in Dispose(), or empty depending data struct
Query: "SELECT category, SUM(value) FROM test_table GROUP BY category LIMIT 0",
Expected: []sql.Row{},
},
{
Query: "SELECT category, COUNT(*) FROM test_table GROUP BY category LIMIT 0",
Expected: []sql.Row{},
},
{
Query: "SELECT SUM(value) FROM test_table LIMIT 0",
Expected: []sql.Row{},
},
},
},
{
// https://github.com/dolthub/dolt/issues/9935
Dialect: "mysql",
Expand Down
4 changes: 3 additions & 1 deletion sql/rowexec/agg.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func (i *groupByIter) Close(ctx *sql.Context) error {

func (i *groupByIter) Dispose() {
for _, b := range i.buf {
b.Dispose()
if b != nil {
b.Dispose()
}
}
}

Expand Down