Description
The Writer is unclosed after usage, which may leak memory:
|
w, err := cs.Writer(ctx2, content.WithRef(ref), content.WithDescriptor(ocispec.Descriptor{Size: size, Digest: d})) |
|
w, err := cs.Writer(ctx2, content.WithRef(ref), content.WithDescriptor(ocispec.Descriptor{Size: size, Digest: d})) |
|
w, err := cs.Writer(ctx2, content.WithRef(ref), content.WithDescriptor(ocispec.Descriptor{Size: size, Digest: d})) |
Steps to reproduce the issue
No response
Describe the results you received and expected
Consider the one:
|
w, err := cs.Writer(ctx2, content.WithRef(ref), content.WithDescriptor(ocispec.Descriptor{Size: size, Digest: d})) |
w is of type
content.Writer that contains a closer. Here
w is not closed after the usage. It should be closed explicitly as demonstrated in another place in the same source file:
|
w2, err := cs.Writer(ctx, content.WithRef("c2"), content.WithDescriptor(ocispec.Descriptor{Size: int64(len(c2))})) |
|
if err != nil { |
|
t.Fatal(err) |
|
} |
|
defer w2.Close() |
Note that w will not be closed within checkNewlyCreated() either:
|
func checkNewlyCreated(t *testing.T, w content.Writer, preStart, postStart, preUpdate, postUpdate time.Time) { |
|
t.Helper() |
|
st, err := w.Status() |
|
if err != nil { |
|
t.Fatalf("failed to get status: %v", err) |
|
} |
|
|
|
wd := w.Digest() |
Fix
While this may not be a real issue depending on the underlying logic and the concrete resource and memory consumption, it is cleaner and safer to explicitly close the write after the usage, as so in other cases.
w, err := cs.Writer(ctx2, content.WithRef(ref), content.WithDescriptor(ocispec.Descriptor{Size: size, Digest: d}))
defer w.Close()
if err != nil {
t.Fatal(err)
}
Found by static analyzer "DeepGo"
What version of containerd are you using?
Current github version
Any other relevant information
No response
Show configuration if it is related to CRI plugin.
No response
Description
The
Writeris unclosed after usage, which may leak memory:containerd/content/testsuite/testsuite.go
Line 939 in d193dc2
containerd/content/testsuite/testsuite.go
Line 819 in d193dc2
containerd/content/testsuite/testsuite.go
Line 877 in d193dc2
Steps to reproduce the issue
No response
Describe the results you received and expected
Consider the one:
containerd/content/testsuite/testsuite.go
Line 939 in d193dc2
wis of typecontent.Writerthat contains a closer. Herewis not closed after the usage. It should be closed explicitly as demonstrated in another place in the same source file:containerd/content/testsuite/testsuite.go
Lines 154 to 158 in d193dc2
Note that
wwill not be closed withincheckNewlyCreated()either:containerd/content/testsuite/testsuite.go
Lines 992 to 999 in d193dc2
Fix
While this may not be a real issue depending on the underlying logic and the concrete resource and memory consumption, it is cleaner and safer to explicitly close the write after the usage, as so in other cases.
Found by static analyzer "DeepGo"
What version of containerd are you using?
Current github version
Any other relevant information
No response
Show configuration if it is related to CRI plugin.
No response