forked from mirror/gorm
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...,
|
db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...,
|
||||||
)
|
)
|
||||||
if db.AddError(err) == nil {
|
if db.AddError(err) == nil {
|
||||||
gorm.Scan(rows, db, mode)
|
defer func() {
|
||||||
db.AddError(rows.Close())
|
db.AddError(rows.Close())
|
||||||
|
}()
|
||||||
|
gorm.Scan(rows, db, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,8 +20,10 @@ func Query(db *gorm.DB) {
|
||||||
db.AddError(err)
|
db.AddError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gorm.Scan(rows, db, 0)
|
defer func() {
|
||||||
db.AddError(rows.Close())
|
db.AddError(rows.Close())
|
||||||
|
}()
|
||||||
|
gorm.Scan(rows, db, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue