Skip to content

Commit

Permalink
server: fix memtracker leak with cursor (pingcap#44257) (pingcap#44825)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jun 20, 2023
1 parent 330cad1 commit 128bf15
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions server/conn_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (cc *clientConn) handleStmtExecute(ctx context.Context, data []byte) (err e
func (cc *clientConn) executePreparedStmtAndWriteResult(ctx context.Context, stmt PreparedStatement, args []types.Datum, useCursor bool) (bool, error) {
vars := (&cc.ctx).GetSessionVars()
rs, err := stmt.Execute(ctx, args)
if rs != nil {
defer terror.Call(rs.Close)
}
if err != nil {
return true, errors.Annotate(err, cc.preparedStmt2String(uint32(stmt.ID())))
}
Expand Down Expand Up @@ -284,17 +287,9 @@ func (cc *clientConn) executePreparedStmtAndWriteResult(ctx context.Context, stm
cl.OnFetchReturned()
}

// as the `Next` of `ResultSet` will never be called, all rows have been cached inside it. We could close this
// `ResultSet`.
err = rs.Close()
if err != nil {
return false, err
}

// explicitly flush columnInfo to client.
return false, cc.flush(ctx)
}
defer terror.Call(rs.Close)
retryable, err := cc.writeResultset(ctx, rs, true, 0, 0)
if err != nil {
return retryable, errors.Annotate(err, cc.preparedStmt2String(uint32(stmt.ID())))
Expand Down

0 comments on commit 128bf15

Please sign in to comment.