local tmpfile may be not closed when 'DownloadFromContainer' returns err#10325
local tmpfile may be not closed when 'DownloadFromContainer' returns err#10325openshift-bot merged 1 commit intoopenshift:masterfrom
Conversation
| @@ -272,7 +279,7 @@ func copyImageSource(dockerClient DockerClient, containerID, sourceDir, destDir | |||
| if err := tempFile.Close(); err != nil { | |||
There was a problem hiding this comment.
Would it be easier to just tempFile.Close() before returning the 270/277 error?
if err != nil {
tempFile.Close()
return err
}
|
we really don't care about this because it's happening inside a container that's about to be thrown away if we get an error, so cleaning up is moot. |
|
but if we do want to make any change, i agree w/ @oatmealraisin that that seems like the simpler fix. |
|
and for that matter do we even know that |
|
thanks @bparees @oatmealraisin yeah, I agree this way can fix this PR more easier. I think it is not good coding style, even through it's happening inside a container, more or less, our code should not too much rely on what environment it will be run. if err != nil { I read some our code that handle such problem like this. In file host.go |
taking advantage of the environment the code is going to run in is a reasonable optimization as long as you understand the assumptions you've made.
no because it's already being closed right after the error check. the only possible exit in the code today that doesn't result in closing the file, is if |
|
@bparees thanks for you suggestion, maybe I'm thinking too much. Yes, the real question is the file not be closed when |
that was @oatmealraisin's original suggestion and i agree with it, yes. Except, again, that before we go adding a close on the file, we should convince ourselves that DownloadFromContainer hasn't already closed the file in the case that it is returning an error. |
2664b61 to
bf08a33
Compare
|
@bparees I think it is difficult to confirm whether it is returning a error when the file not be closed. Maybe the error will never happen. But When I read the code I feel a little confusing, more or less. |
bf08a33 to
e7e397a
Compare
…urns err add file close when return err run go fmt go fmt
|
@guangxuli i've reviewed the DownloadFromContainer function, it does not close the stream when returning an error. lgtm [merge] |
|
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7835/) (Image: devenv-rhel7_4811) |
|
Evaluated for origin merge up to e7e397a |
|
[Test]ing while waiting on the merge queue |
|
Evaluated for origin test up to e7e397a |
|
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7826/) |
In function copyImageSource, if dockerClient.DownloadFromContainer returns err, tempFile will not be closed.