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 {
|
||||||
|
defer func() {
|
||||||
|
db.AddError(rows.Close())
|
||||||
|
}()
|
||||||
gorm.Scan(rows, db, mode)
|
gorm.Scan(rows, db, mode)
|
||||||
db.AddError(rows.Close())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,8 +20,10 @@ func Query(db *gorm.DB) {
|
||||||
db.AddError(err)
|
db.AddError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
db.AddError(rows.Close())
|
||||||
|
}()
|
||||||
gorm.Scan(rows, db, 0)
|
gorm.Scan(rows, db, 0)
|
||||||
db.AddError(rows.Close())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue