Skip to content
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

Fix a resource leak when open a lfs file #22043

Closed
wants to merge 1 commit into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Dec 6, 2022

No description provided.

@lunny lunny added type/bug backport/v1.17 outdated/backport/v1.18 This PR should be backported to Gitea 1.18 labels Dec 6, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #22043 (ee84390) into main (77f5035) will increase coverage by 48.15%.
The diff coverage is 0.00%.

@@            Coverage Diff            @@
##           main   #22043       +/-   ##
=========================================
+ Coverage      0   48.15%   +48.15%     
=========================================
  Files         0     1037     +1037     
  Lines         0   141409   +141409     
=========================================
+ Hits          0    68100    +68100     
- Misses        0    65173    +65173     
- Partials      0     8136     +8136     
Impacted Files Coverage Δ
routers/web/repo/view.go 43.53% <0.00%> (ø)
routers/api/v1/repo/issue_tracked_time.go 38.66% <0.00%> (ø)
models/asymkey/ssh_key_deploy.go 55.24% <0.00%> (ø)
routers/api/v1/repo/subscriber.go 0.00% <0.00%> (ø)
models/organization/team_unit.go 21.05% <0.00%> (ø)
modules/git/remote.go 71.42% <0.00%> (ø)
services/webhook/matrix.go 73.38% <0.00%> (ø)
routers/web/goget.go 73.01% <0.00%> (ø)
modules/git/repo_tag_nogogit.go 46.66% <0.00%> (ø)
modules/git/blob_nogogit.go 62.02% <0.00%> (ø)
... and 1028 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 6, 2022
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 6, 2022
@silverwind
Copy link
Member

silverwind commented Dec 6, 2022

There is defer dataRc.Close() on line 255, shouldn't it take effect when the function returns?

Also, we probably shouldn't shadow the dataRc variable here.

@wxiaoguang
Copy link
Contributor

There is defer dataRc.Close() on line 255, shouldn't it take effect when the function returns?

Also, we probably shouldn't shadow the dataRc variable here.

Yup, and even more, line 410

@lunny
Copy link
Member Author

lunny commented Dec 6, 2022

There is defer dataRc.Close() on line 255, shouldn't it take effect when the function returns?

Also, we probably shouldn't shadow the dataRc variable here.

This will close the previous dataRc because the next lines will override the dataRc variable.
I also don't like the shadown, so I created #22042 to resolve them. But for backport, this is also necessary.

@KN4CK3R
Copy link
Member

KN4CK3R commented Dec 6, 2022

Is the double defer dataRc.Close() correct? The docs say

The behavior of Close after the first call is undefined.

@silverwind
Copy link
Member

This will close the previous dataRc because the next lines will override the dataRc variable.

But the previous Close should still execute on the first instance, right? When does go resolve the variable? At time of parsing or at time when the deferexecutes?

@lunny
Copy link
Member Author

lunny commented Dec 6, 2022

Looks like this PR is unnecessary. see https://go.dev/play/p/2d8BuU5ZVeg

@lunny lunny closed this Dec 6, 2022
@silverwind
Copy link
Member

I'm actually quiet surprised that the code executed during defer sees the variable before the shadowing. I would have thought because defer executes last, it should see the last instance of the variable.

@lunny lunny deleted the lunny/fix_read_bug branch December 6, 2022 09:39
@zeripath zeripath removed backport/v1.17 outdated/backport/v1.18 This PR should be backported to Gitea 1.18 labels Jan 13, 2023
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants