Fix memory leaks with SQLite prepared statements (#2253)

This commit is contained in:
Neil Alexander 2022-03-04 15:05:42 +00:00 committed by GitHub
parent 5e694cd362
commit 22a034dcba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 20 deletions

View file

@ -113,11 +113,12 @@ func (s *stateSnapshotStatements) BulkSelectStateBlockNIDs(
nids[k] = v
}
selectOrig := strings.Replace(bulkSelectStateBlockNIDsSQL, "($1)", sqlutil.QueryVariadic(len(nids)), 1)
selectStmt, err := s.db.Prepare(selectOrig)
selectPrep, err := s.db.Prepare(selectOrig)
if err != nil {
return nil, err
}
selectStmt = sqlutil.TxStmt(txn, selectStmt)
defer selectPrep.Close() // nolint:errcheck
selectStmt := sqlutil.TxStmt(txn, selectPrep)
rows, err := selectStmt.QueryContext(ctx, nids...)
if err != nil {