diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2021-08-23 21:47:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-24 01:47:22 +0000 |
| commit | 286caed92beb805947be348b3dff18e24b52b42c (patch) | |
| tree | d50dfdcc91a3e11f5ee08fb062e40f72cfe7da22 /data | |
| parent | be57b2d2cfde988e410f64abb2029c6005894fbe (diff) | |
Fix a few filehandle leaks (#1199)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'data')
| -rw-r--r-- | data/datasource_file.go | 2 | ||||
| -rw-r--r-- | data/datasource_file_test.go | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/data/datasource_file.go b/data/datasource_file.go index a94944cd..175f92f0 100644 --- a/data/datasource_file.go +++ b/data/datasource_file.go @@ -51,6 +51,8 @@ func readFile(source *Source, args ...string) ([]byte, error) { return nil, errors.Wrapf(err, "Can't open %s", p) } + defer f.Close() + b, err := ioutil.ReadAll(f) if err != nil { return nil, errors.Wrapf(err, "Can't read %s", p) diff --git a/data/datasource_file_test.go b/data/datasource_file_test.go index 6cbcacd7..aa51dbca 100644 --- a/data/datasource_file_test.go +++ b/data/datasource_file_test.go @@ -21,6 +21,7 @@ func TestReadFile(t *testing.T) { _, _ = f.Write(content) _, _ = fs.Create("/tmp/partial/bar.txt") _, _ = fs.Create("/tmp/partial/baz.txt") + _ = f.Close() source := &Source{Alias: "foo", URL: mustParseURL("file:///tmp/foo")} source.fs = fs |
