Consider the following code:
f, err := os.Create(tmpFilepath)
defer f.Close()
// do some writing to f
os.Rename(tmpFilepath, newpath)
Some error handling has been removed to simplify.
Also, I know this code is wrong, but I am trying to understand what is the effect of this code in term of correctness of the files, and in terms of performance.
Is there a resource leak here?
By the way, the fix is to close when you are done writing to the file.