Skip to content

Commit da2d772

Browse files
committed
privilege/privileges: don't reuse chunk in loadTable function (pingcap#6976)
1 parent b236944 commit da2d772

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

privilege/privileges/cache.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,19 @@ func (p *MySQLPrivilege) loadTable(sctx sessionctx.Context, sql string,
183183
defer terror.Call(rs.Close)
184184

185185
fs := rs.Fields()
186-
chk := rs.NewChunk()
187-
it := chunk.NewIterator4Chunk(chk)
188186
for {
187+
// NOTE: decodeTableRow decodes data from a chunk Row, that is a shallow copy.
188+
// The result will reference memory in the chunk, so the chunk must not be reused
189+
// here, otherwise some werid bug will happen!
190+
chk := rs.NewChunk()
189191
err = rs.Next(context.TODO(), chk)
190192
if err != nil {
191193
return errors.Trace(err)
192194
}
193195
if chk.NumRows() == 0 {
194196
return nil
195197
}
198+
it := chunk.NewIterator4Chunk(chk)
196199
for row := it.Begin(); row != it.End(); row = it.Next() {
197200
err = decodeTableRow(row, fs)
198201
if err != nil {

0 commit comments

Comments
 (0)