From 3998b5bbec5244f48c83968d440c2b23a9ea1686 Mon Sep 17 00:00:00 2001 From: liang chenye Date: Fri, 20 May 2016 10:43:29 +0800 Subject: [PATCH] close io reader in debian/rhel fetchers Signed-off-by: liang chenye --- updater/fetchers/debian/debian.go | 1 + updater/fetchers/debian/debian_test.go | 1 + updater/fetchers/rhel/rhel.go | 1 + updater/fetchers/rhel/rhel_test.go | 2 ++ 4 files changed, 5 insertions(+) diff --git a/updater/fetchers/debian/debian.go b/updater/fetchers/debian/debian.go index e21bd3f2..356613eb 100644 --- a/updater/fetchers/debian/debian.go +++ b/updater/fetchers/debian/debian.go @@ -69,6 +69,7 @@ func (fetcher *DebianFetcher) FetchUpdate(datastore database.Datastore) (resp up log.Errorf("could not download Debian's update: %s", err) return resp, cerrors.ErrCouldNotDownload } + defer r.Body.Close() // Get the SHA-1 of the latest update's JSON data latestHash, err := datastore.GetKeyValue(updaterFlag) diff --git a/updater/fetchers/debian/debian_test.go b/updater/fetchers/debian/debian_test.go index e092909d..88000af1 100644 --- a/updater/fetchers/debian/debian_test.go +++ b/updater/fetchers/debian/debian_test.go @@ -31,6 +31,7 @@ func TestDebianParser(t *testing.T) { // Test parsing testdata/fetcher_debian_test.json testFile, _ := os.Open(filepath.Join(filepath.Dir(filename)) + "/testdata/fetcher_debian_test.json") response, err := buildResponse(testFile, "") + defer testFile.Close() if assert.Nil(t, err) && assert.Len(t, response.Vulnerabilities, 3) { for _, vulnerability := range response.Vulnerabilities { if vulnerability.Name == "CVE-2015-1323" { diff --git a/updater/fetchers/rhel/rhel.go b/updater/fetchers/rhel/rhel.go index de4072d1..8d31f309 100644 --- a/updater/fetchers/rhel/rhel.go +++ b/updater/fetchers/rhel/rhel.go @@ -107,6 +107,7 @@ func (f *RHELFetcher) FetchUpdate(datastore database.Datastore) (resp updater.Fe log.Errorf("could not download RHEL's update list: %s", err) return resp, cerrors.ErrCouldNotDownload } + defer r.Body.Close() // Get the list of RHSAs that we have to process. var rhsaList []int diff --git a/updater/fetchers/rhel/rhel_test.go b/updater/fetchers/rhel/rhel_test.go index 0e9ddbd0..b7fb9818 100644 --- a/updater/fetchers/rhel/rhel_test.go +++ b/updater/fetchers/rhel/rhel_test.go @@ -32,6 +32,7 @@ func TestRHELParser(t *testing.T) { // Test parsing testdata/fetcher_rhel_test.1.xml testFile, _ := os.Open(path + "/testdata/fetcher_rhel_test.1.xml") vulnerabilities, err := parseRHSA(testFile) + testFile.Close() if assert.Nil(t, err) && assert.Len(t, vulnerabilities, 1) { assert.Equal(t, "RHSA-2015:1193", vulnerabilities[0].Name) assert.Equal(t, "https://rhn.redhat.com/errata/RHSA-2015-1193.html", vulnerabilities[0].Link) @@ -70,6 +71,7 @@ func TestRHELParser(t *testing.T) { // Test parsing testdata/fetcher_rhel_test.2.xml testFile, _ = os.Open(path + "/testdata/fetcher_rhel_test.2.xml") vulnerabilities, err = parseRHSA(testFile) + testFile.Close() if assert.Nil(t, err) && assert.Len(t, vulnerabilities, 1) { assert.Equal(t, "RHSA-2015:1207", vulnerabilities[0].Name) assert.Equal(t, "https://rhn.redhat.com/errata/RHSA-2015-1207.html", vulnerabilities[0].Link)