Bugfix: eliminate 2nd call to Close() #51
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While researching your answer in #50 I came across a bug, and am submitting the fix which is simple.
The method
qrcode.Save()
is callingClose()
too many times. In my test code this was causing problems as follows:In this test
qrcode.Save()
uses the standard writer'sWrite()
method which callsdrawTo()
which begins processing 4k chunks normally. WhendrawTo()
completes and returns up the stack tostandard.Writer.Write()
adefer
callsClose()
for the first time. This causes my test code to report the size of the Buffer. Control passes up the stack back to theqrcode.Save()
method which calls.Close()
once again. This causes my test code to again report the size of the Buffer which is now zero.This is obviously not desirable and potentially causes problems for some custom writers. The question becomes, "Which Close() should be eliminated?" I think the answer to that is easy, the
defer
in theWrite()
method makes much more sense to eliminate. Having theWrite()
andClose()
together inqrcode.Save()
is much more readable and proper.This PR eliminates the superfluous deferred call to
Close()
in the standard writer.@BuckeyeCoder