mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2025-07-08 23:58:31 +00:00
Check error before deferring db.Close() (#491)
This commit is contained in:
parent
b9be7daa4a
commit
09fb3c4fe4
@ -49,11 +49,11 @@ func savePgsql(jsonInfo string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db, err := gorm.Open("postgres", connInfo)
|
db, err := gorm.Open("postgres", connInfo)
|
||||||
defer db.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitWithError(fmt.Errorf("received error connecting to database: %s", err))
|
exitWithError(fmt.Errorf("received error connecting to database: %s", err))
|
||||||
}
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
db.Debug().AutoMigrate(&ScanResult{})
|
db.Debug().AutoMigrate(&ScanResult{})
|
||||||
db.Save(&ScanResult{ScanHost: hostname, ScanTime: timestamp, ScanInfo: jsonInfo})
|
db.Save(&ScanResult{ScanHost: hostname, ScanTime: timestamp, ScanInfo: jsonInfo})
|
||||||
glog.V(2).Info(fmt.Sprintf("successfully stored result to: %s", envVars["PGSQL_HOST"]))
|
glog.V(2).Info(fmt.Sprintf("successfully stored result to: %s", envVars["PGSQL_HOST"]))
|
||||||
|
Loading…
Reference in New Issue
Block a user