New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
all: resource leaks due to missing .Close() calls in various conditions #55081
Comments
Change https://go.dev/cl/430997 mentions this issue: |
@odeke-em I think the flag for base64 encoder seems wrong, calling Close just to make sure partial data will be written, the encoder can still be gc-ed even without calling Close:
|
@cuonglm While some of these may be false positives, the fact that the encoder can be garbage collected does not demonstrate the lack of a leak. If for example Also, even when there is a proper finalizer set (as is the case for |
@rittneje Yeah, that's why I only describe specifically for base64 encoder. The example demonstrate that we don't leak the writer. |
My point is that you can really only conclude there is no leak at all by examining the source code of |
Not sure why not mean much. You seem to describe the fd leaks case, while my example above demonstrate that there's no memory leak in case of base64 encoder because the encoder was gc-ed. |
Even this is contingent upon the implementation of |
Not sure how can it be counter-example:
|
The |
Of course the garbage collector cannot do anything, and your example is different from the original demonstration with the base64 encoder. I just mean showing the length of the global slice does not mean anything. If you remove the reference without modifying the global slice length, they're still gc-ed. |
I tend to agree that we should not worry about calling |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Irrelevant
What did you do?
Ran a static analyzer developed at Orijtech Inc called "staticmajor" and available on Github actions per https://github.com/marketplace/actions/staticmajor-analyzer and it produced a laundry list of leaking resources like for example
go/src/compress/flate/deflate.go
Lines 665 to 670 in 972870d
in which the return on line 668 doesn't invoke
dw.Close()
which leaks the Writeror
go/src/encoding/pem/pem.go
Lines 291 to 294 in 972870d
in which the return on line 293 doesn't invoke
b64.Close()
What did you expect to see?
No resource leaks
What did you see instead?
The laundry list is
Just an FYI to @eliasnaur @kirbyquerby @willpoint @jhusdero
The text was updated successfully, but these errors were encountered: