mirror of https://github.com/go-gorm/gorm.git
Use defer to close rows to avoid scan panic leak rows
This commit is contained in:
parent
9dd6ed9c65
commit
ea8509b777
|
@ -84,8 +84,10 @@ func Create(config *Config) func(db *gorm.DB) {
|
|||
db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...,
|
||||
)
|
||||
if db.AddError(err) == nil {
|
||||
defer func() {
|
||||
db.AddError(rows.Close())
|
||||
}()
|
||||
gorm.Scan(rows, db, mode)
|
||||
db.AddError(rows.Close())
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -20,8 +20,10 @@ func Query(db *gorm.DB) {
|
|||
db.AddError(err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
db.AddError(rows.Close())
|
||||
}()
|
||||
gorm.Scan(rows, db, 0)
|
||||
db.AddError(rows.Close())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue