close geoip db on shutdown

This commit is contained in:
Sebastien Blot 2024-04-17 09:54:55 +02:00
parent bdc62d3715
commit 5f0044d276
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
2 changed files with 15 additions and 0 deletions

View file

@ -177,6 +177,9 @@ func ShutdownCrowdsecRoutines() error {
// He's dead, Jim.
crowdsecTomb.Kill(nil)
// close the potential geoips reader we have to avoid leaking ressources on reload
exprhelpers.GeoIPClose()
return reterr
}

View file

@ -102,6 +102,18 @@ func GeoIPInit(datadir string) error {
return nil
}
func GeoIPClose() {
if geoIPCityReader != nil {
geoIPCityReader.Close()
}
if geoIPASNReader != nil {
geoIPASNReader.Close()
}
if geoIPRangeReader != nil {
geoIPRangeReader.Close()
}
}
func Init(databaseClient *database.Client) error {
dataFile = make(map[string][]string)
dataFileRegex = make(map[string][]*regexp.Regexp)