From a692cec0ef3f574f94d26d084a18bf71f69dcbae Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Wed, 21 Apr 2021 11:59:11 +0900 Subject: [PATCH] fix(gost): close gost DB connection in server mode #1217 (#1221) --- detector/detector.go | 6 ++++++ gost/gost.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/detector/detector.go b/detector/detector.go index c1140cd0..12c5a186 100644 --- a/detector/detector.go +++ b/detector/detector.go @@ -369,6 +369,12 @@ func detectPkgsCvesWithGost(cnf config.GostConf, r *models.ScanResult) error { return xerrors.Errorf("Failed to new a gost client: %w", err) } + defer func() { + if err := client.CloseDB(); err != nil { + logging.Log.Errorf("Failed to close the gost DB. err: %+v", err) + } + }() + nCVEs, err := client.DetectUnfixed(r, true) if err != nil { return xerrors.Errorf("Failed to detect unfixed CVEs with gost: %w", err) diff --git a/gost/gost.go b/gost/gost.go index bccca379..87a0a420 100644 --- a/gost/gost.go +++ b/gost/gost.go @@ -21,6 +21,7 @@ type DBDriver struct { // Client is the interface of OVAL client. type Client interface { DetectUnfixed(*models.ScanResult, bool) (int, error) + CloseDB() error } // Base is a base struct @@ -28,6 +29,10 @@ type Base struct { DBDriver DBDriver } +func (b Base) CloseDB() error { + return b.DBDriver.DB.CloseDB() +} + // FillCVEsWithRedHat fills CVE detailed with Red Hat Security func FillCVEsWithRedHat(r *models.ScanResult, cnf config.GostConf) error { db, locked, err := newGostDB(cnf)