Skip to content

Files are opened but never closed #471

Closed
@dholbach

Description

@dholbach

From Ada Logics

There are two occurrences in Helmchart controller where a file is opened but never closed here and here. This can lead to resource leaks and exhaustion of available file descriptors in the process. An example of the code pattern is shown here:

indexFile, err :=
os.Open(r.Storage.LocalPath(*repository.GetArtifact()))
if err != nil {
     return sourcev1.HelmChartNotReady(chart,
sourcev1.StorageOperationFailedReason, err.Error()), err
}
b, err := io.ReadAll(indexFile)

Recommendation

Fix the file descriptor leak by appropriately closing opened files. This can be performed with a deferred indexFile.Close() operation

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions