diff --git a/pkg/collector/corechecks/servicediscovery/usm/nodejs.go b/pkg/collector/corechecks/servicediscovery/usm/nodejs.go index aa4d3997c7d27..6a39be2b41dda 100644 --- a/pkg/collector/corechecks/servicediscovery/usm/nodejs.go +++ b/pkg/collector/corechecks/servicediscovery/usm/nodejs.go @@ -96,6 +96,7 @@ func (n nodeDetector) maybeExtractServiceName(filename string) (string, bool) { if err != nil { return "", false } + defer file.Close() ok, err := canSafelyParse(file) if err != nil { //file not accessible or don't exist. Continuing searching up diff --git a/pkg/collector/corechecks/servicediscovery/usm/tomcat.go b/pkg/collector/corechecks/servicediscovery/usm/tomcat.go index 587dbc2dc9f9a..0271bd6772010 100644 --- a/pkg/collector/corechecks/servicediscovery/usm/tomcat.go +++ b/pkg/collector/corechecks/servicediscovery/usm/tomcat.go @@ -132,6 +132,7 @@ func (te tomcatExtractor) parseServerXML(domainHome string) *tomcatServerXML { log.Debugf("Unable to locate tomcat server.xml (%q). Err: %v", xmlFilePath, err) return nil } + defer file.Close() var serverXML tomcatServerXML err = xml.NewDecoder(file).Decode(&serverXML) if err != nil {